Click here to Skip to main content
16,021,765 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
I want to get two table with name's "Orders_T" and "Domain_T" data with a query in asp.net but my query dose not work:
SQL
SELECT * FROM dbo.Orders_T
UNION all
SELECT *
FROM   dbo.Domain_T

Please help me.
thank you for your help.
Posted
Updated 23-Jul-11 22:08pm
v2
Comments
Uday P.Singh 24-Jul-11 4:27am    
what error message are you getting?

Make sure the number of columns and the column names of your 2 tables are the same if you want it to work. You may want to specify the column names instead of putting *, like this.

SQL
SELECT fName, mName, lName FROM tblEmployeeInfo
UNION ALL
SELECT fName, mName, lName FROM tblStudentInfo
 
Share this answer
 
Comments
Abhinav S 24-Jul-11 4:17am    
Good and precise answer. My 5.
walterhevedeich 24-Jul-11 4:23am    
Thank you.
Hassan Sajedi 24-Jul-11 4:18am    
My tables row numbers are not equal:
"SELECT id, Code, Title, Amount, PayType, PayDate, MaturityPayDate, UID, Description
FROM dbo.Orders_T
UNION ALL
SELECT id, Name, Amount, UID
FROM dbo.Domain_T"
Whether this is done? if is not to Implementation this query please send me another idea to done that.
thank you.
walterhevedeich 24-Jul-11 4:23am    
You can't do a union with 2 tables that does not have the same number of columns and column names. Please don't get confused by the row numbers. The rows doesn't really matter, only the columns. Perhaps you might want to describe what you want to achieve here so we can better understand your problem.
You need to look at some of the basics of implementing a UNION clause - see here[^].
 
Share this answer
 
Comments
walterhevedeich 24-Jul-11 4:25am    
I believe this will be a great help to get OP educated about UNION. My 5.
Abhinav S 24-Jul-11 4:38am    
Thank you Walter.
Before performing UNION operation must know this:

UNION RULES

1.A UNION must be composed of two or more SELECT statements, each separated by the keyword UNION.
2.Each query in a UNION must contain the same columns, expressions, or aggregate functions, and they must be listed in the same order.

3.Column datatypes must be compatible: They need not be the same exact same type, but they must be of a type that SQL Server can implicitly convert.

hope it helps :)
 
Share this answer
 
Comments
Abhinav S 24-Jul-11 4:39am    
My 5. Hope the OP is able to get going after going through all these answers.
Uday P.Singh 24-Jul-11 4:44am    
thanks Abhinav :)
walterhevedeich 24-Jul-11 4:41am    
5ed too
Uday P.Singh 24-Jul-11 4:44am    
thanks walterhevedeich :)
uspatel 24-Jul-11 9:27am    
these rules are very helpfull.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900