Posted: Tue Dec 26, 2006 12:05 pm
If you do not need anything from table 2 then it's a "simple" query without any JOIN or UNION?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
( query1 ) UNION ( query2 )Code: Select all
"Error 1222 The used SELECT statements have different number of columns"Code: Select all
SELECT Isnull(table2.commonColumnName) AS test ,table1.commonColumnName, table1.otherColumnName FROM table1 LEFT JOIN table2 ON table1.commonColumnName=table2.commonColumnName
UNION
SELECT Isnull(table1.commonColumnName),table2.commonColumnName FROM table2 LEFT JOIN table1 ON table2.commonColumnName=table2.commonColumnName
WHERE ISNULL(table1.commonColumnName)Code: Select all
WHERE 3rdColumnName='$find' AND 4thColumnName LIKE '%$field%'query #1 selects three fields, query #2 only two, the number of columns do not match.volka wrote:As long as the number of fields in the result set match you can do (more or less) anything you like with query1 and query2.
Code: Select all
SELECT Isnull(table1.commonColumnName),table2.commonColumnName,null FROM table2