Click here to Skip to main content
15,888,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends

I have two tables t1 and t2.

Table t1 Structure

Paycode
Name

Table t2 Structure

Paycode
Name

And one more thing there is no concept of primary key and foreign key in my table.

Records in t1

1) 111 sunil
2) 222 sunit

Records in t2

1) 333 narayan
2) 444 sumit

and I want all the records from query.............

Please help me out as soon as possible.
Posted

Try this
select * from t1 UNION ALL select * from t2
 
Share this answer
 
v3
Comments
Maciej Los 11-May-12 8:38am    
Good answer, my 5!
nagendrathecoder 11-May-12 9:05am    
Thanks
The prefer solution is:
SQL
SELECT *
FROM t1
UNION ALL
SELECT *
FROM t2


Read more:
Writing queries - basics[^]
SELECT[^]
SELECT Examples[^]
UNION[^]
ORDER BY[^]
 
Share this answer
 
v2
Comments
nagendrathecoder 11-May-12 9:17am    
select * from t1,t2 will do a cross join which i guess is not the result OP is expected.
Second query is correct one.
Maciej Los 11-May-12 10:00am    
You are right! Thank you ;)
Based on the information you have given about the tables, I'd suggest a redesign of the table structure.

Do you really need to separate the rows to two different tables? Could yo uuse one table instead? If the rows are somehow different, for example rows in the first table are valid while in the other table they are invalid, could you use an extra column to define the state of the row (just an example).
 
Share this answer
 

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