Results 1 to 5 of 5

Thread: problem with join

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    problem with join

    Hi all,

    I have to join three tables, one of the table has id and other fields, the other table has description but for one id, there are more than one description, I need to only pick up one description and other fields from other tables, how would I be able to do it?

    please help.

  2. #2
    Join Date
    May 2004
    Location
    Dunedin, New Zealand
    Posts
    33
    Hi,

    You need to join on the ID's and also the description:

    eg:

    Select tbl1.ID, tbl1.ColA, tbl2.ID, tbl2.Desc, tbl2.Data1
    From tbl1
    inner join tbl2 on tbl1.ID = tbl2.ID and tbl2.Desc = 'Your Description'

    Hope this helps.

    Guytz

  3. #3
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    It won't work in my case because the description is not always the same, I just need to pick any of them randomly...

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    SELECT tbl1.id, tbl2a.MaxDesc
    FROM tbl1 JOIN
    (SELECT id, MAX(description) AS MaxDesc FROM tbl2 GROUP BY id) AS tbl2a
    ON tbl1.id = tbl2a.id

    (you don't have to use MAX - can use MIN if you want - if this doesn't produce unique records, then you need to group by additional columns)
    Last edited by nosepicker; 11-30-2005 at 12:00 PM.

  5. #5
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    it worked, thanks a lot!!!

Posting Permissions

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