Appending one sql query with another
I have a datareader that binds a sql select (with 10 columns from table1) , i want to append another with 5 different cols from table2 to this first sql select, i can't开发者_开发知识库 do UNION as it has different number of columns, (one query has 10, another returns 5 cols).
Is there any other way of implementing this, via mysql?
Also i need to append the additional 5 columns based on a condition, is there via mysql select query to write with using if then in the select query?
Thanks.
What about unioning with nulls? The query below will remove duplicates between the two datasets.
SELECT col1,col2,col3,col4
FROM table1
UNION ALL
SELECT col1,col2,null,null
FROM table2
If you want to remove duplicates inside of each dataset use the query below:
SELECT DISTINCT col1,col2,col3,col4
FROM table1
UNION ALL
SELECT DISTINCT col1,col2,null,null
FROM table2
You can use anything you want for the default value after col1 and col2.
null, 'none', '' all should work.
精彩评论