www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Select from 2 tables

  1. #1
    Join Date
    May 2009
    Posts
    226

    resolved [RESOLVED] Select from 2 tables

    I have 2 tables: lss1 & lss2 and the content needs to be selected from either table depending on the criteria.

    PHP Code:
    $sql="SELECT * FROM lss1, lss2 WHERE id=$variable"
    I am getting the following error: "Couldn't execute query: Column 'id' in where clause is ambiguous"

    How do I not make the "id" ambiguous when it could go to either table?

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    specify id from which table to select. i think you need...

    $sql="SELECT * FROM lss1, lss2 WHERE lss1.id=$variable and lss1.id=lss2.id";

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,918
    If the two tables are truly separate (as opposed to joined on a common field), then you may need to do a union
    PHP Code:
    select col1col2col3 from table1 where something='something'
    union
    select col2
    col2col3 from table2 where something='something' 
    Note that you must select the same number/type of columns from each table.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles