Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    161

    Unanswered: Selecting rows from 2 tables

    Code:
    SELECT *
    FROM `tbl1` t1, `tbl2` t2
    WHERE t1.id=56 AND t2.id = 56
    I need the values from the tables tbl1, tbl2 where the id is 56.
    In tbl2 there may or may not be an id=56 - in that case I would still want the query to return tbl1's row - but that wont happen because of the AND.

    So how do I return the row of tbl1 when tbl2 doesnt have such an id ?
    I know to get this using 2 queries - Im looking for a single query statement.

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    use a LEFT OUTER JOIN
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    161
    Couldnt figure out JOINS so far - can you pl give me the example for the above ? The docs has a section on Optimization on JOINS but no example of JOINS usage.

    Edit : I got this working with LEFT JOIN alone. Thanks.
    Last edited by anjanesh; 02-15-06 at 02:44.

Posting Permissions

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