Results 1 to 3 of 3

Thread: [RESOLVED] Select from 2 tables

  1. #1
    Join Date
    May 2009

    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
    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
    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'
    select col2
    col2col3 from table2 where something='something' 
    Note that you must select the same number/type of columns from each table.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

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