Professional Web Applications Themes

select top question - Microsoft SQL / MS SQL Server

Hi, Here's what I'm trying to do : select * from tableA + select * from tableB where tableB.field1 = tableA.field1 + select top1 from tableC where tableC.field1 = tableA.field1 Is it possible ? how ? Thanks a lot. Sam...

  1. #1

    Default select top question

    Hi,

    Here's what I'm trying to do :

    select * from tableA
    +
    select * from tableB where tableB.field1 = tableA.field1
    +
    select top1 from tableC where tableC.field1 = tableA.field1

    Is it possible ? how ?

    Thanks a lot.

    Sam


    Samuel Nadeau Guest

  2. #2

    Default Re: select top question

    Are you doing a UNION or join? What does '+' mean? Or is this an arithmetic
    operation between the columns in the SELECT list?

    --
    - Anith
    ( Please reply to newsgroups only )


    Anith Sen Guest

  3. #3

    Default Re: select top question

    How about something like:


    SELECT * FROM
    tableA a
    INNER JOIN tableB b
    ON
    a.column1 = b.column1
    INNER JOIN (
    SELECT column1, somethingElse = MAX(somethingElse)
    FROM tableC GROUP BY column1
    ) c
    ON
    a.column1 = c.column1


    Without table structure, sample data, and desired results, it's going to be
    pretty for anyone to hand you a solution that works as is.




    "Samuel Nadeau" <samnadeausypatico.ca> wrote in message
    news:#ZBLoN9RDHA.2408TK2MSFTNGP10.phx.gbl...
    > Yes, the + means I'm trying to JOIN the result of all thoses queries
    > together.
    >
    > Sam
    >
    >
    > "Anith Sen" <anithbizdatasolutions.com> wrote in message
    > news:uOyrIH8RDHA.704tk2msftngp13.phx.gbl...
    > > Are you doing a UNION or join? What does '+' mean? Or is this an
    > arithmetic
    > > operation between the columns in the SELECT list?
    > >
    > > --
    > > - Anith
    > > ( Please reply to newsgroups only )
    > >
    > >
    >
    >

    Aaron Bertrand - MVP Guest

  4. #4

    Default select top question

    I would use:

    SELECT A.*, B.*, C.top1 FROM
    tableA A
    INNER JOIN tableB B
    ON a.column1 = b.column1
    INNER JOIN tableC C
    ON a.column1 = c.column1
    Bob Noll Guest

  5. #5

    Default Re: select top question

    Try

    select
    *
    from
    tableA
    INNER JOIN
    tableB
    ON
    tableB.field1 = tableA.field1
    INNER JOIN
    (select top 1 * from tableC where tableC.field1 = tableA.field1) SubQ
    ON
    SubQ.field1 = tableA.field1

    "Samuel Nadeau" <ca> wrote in message
    news:OU1PV%phx.gbl... 


    James Guest

Similar Threads

  1. Quick Select Question
    By amerar@iwc.net in forum MySQL
    Replies: 3
    Last Post: February 1st, 04:44 PM
  2. SQL Select question
    By megalith in forum Coldfusion Database Access
    Replies: 2
    Last Post: October 24th, 06:44 PM
  3. Question on a select
    By Madison Kelly in forum PostgreSQL / PGSQL
    Replies: 10
    Last Post: January 2nd, 03:45 PM
  4. Select question
    By Largo SQL Tools in forum Informix
    Replies: 8
    Last Post: November 10th, 10:44 PM
  5. a question of select()-ion
    By John Galt in forum UNIX Programming
    Replies: 9
    Last Post: July 25th, 08:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139