mysql table help
Moderator: General Moderators
Code: Select all
( query1 ) UNION ( query2 )Hi Volka
I tried to run 2 queriesseparately, they work fine individually and I can retrieve more column values from table1 also but as soon as I use UNION with these 2 queries, it gives me error like
I am trying these queries as
with this query1(not query2), I am trying to use the WHERE CLAUSE as
I know its a complex query and without your help, I can't make it working. I tried to explain my best, hope I will get some reply soon.
Thanks
I tried to run 2 queriesseparately, they work fine individually and I can retrieve more column values from table1 also but as soon as I use UNION with these 2 queries, it gives me error like
Code: Select all
"Error 1222 The used SELECT statements have different number of columns"I am trying these queries as
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%'Thanks
There was only one condition
Select a third field/value in you second query, e.g. NULL.
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.
Select a third field/value in you second query, e.g. NULL.
Code: Select all
SELECT Isnull(table1.commonColumnName),table2.commonColumnName,null FROM table2