[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.
I am getting the following error: "Couldn't execute query: Column 'id' in where clause is ambiguous"
$sql="SELECT * FROM lss1, lss2 WHERE id=$variable";
How do I not make the "id" ambiguous when it could go to either table?
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";
If the two tables are truly separate (as opposed to joined on a common field), then you may need to do a union
Note that you must select the same number/type of columns from each table.
select col1, col2, col3 from table1 where something='something'
select col2, col2, col3 from table2 where something='something'
"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
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)