Join / Union help needed

I am having trouble retrieving data from 2 tables, I have the following

$sql = mysql_query("SELECT * FROM table1 WHERE table1.cell = '$value' JOIN SELECT * FROM  table2 WHERE table2.cell = '$value'", $db_con);

I have also tried

$sql = mysql_query("SELECT * FROM table1 WHERE table1.cell = '$value' UNION SELECT * FROM  table2 WHERE table2.cell = '$value'", $db_con);

but i am not getting any results.

When i try

$sql = mysql_query("SELECT * FROM table1 WHERE table1.cell = '$value'", $db_con);

and

$sql = mysql_query("SELECT * FROM  table2 WHERE table2.cell = '$value'", $db_con);

and i get the results from each table.

Can someone tell me where I have gone wrong :evil:

First of all, read up on what JOIN and UNION do, and figure out which one you actually need. They’re not interchangeable.
Furthermore, your syntax for JOIN is off, and I presume the syntax for your UNION statement is as well.

Sponsor our Newsletter | Privacy Policy | Terms of Service