How to UNION ALL two SELECT statements?
- by Lisa
I have 2 tables, one looks like this:
TABLE ONE
id | Last Name | First Name | Username | Password | Secret Question
and another that looks like this:
TABLE TWO
id | Hobby | Country |
I want to combine a Select statement that grabs data from both tables and output the results. The following code:
$select = mysql_query("
SELECT * FROM table_one WHERE Username = 'Bob'
UNION ALL
SELECT * FROM table_two WHERE Hobby = 'Baseball'
");
while ($return = mysql_fetch_assoc($select)) {
$userName = $return['Username'];
$hobby = $return['Hobby'];
}
echo "$userName likes $hobby";
results in a The used SELECT statements have a different number of columns error, what am I doing wrong?