Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys

Just like I have one table and two queries and both queries get different data from both table but the field name of both are same but i want that the table generate by the two queries will be one but with ddifferent fields .

eg Orignal table like this

id name age
1 Abc 12
2 aba 13
3 abb 13
4 bca 10
and queries are
1 select * from table_name where age=12
2 select * from table_name where age=13

and I want resulted table is

id name age id1 name1 age1
1 abc 12 2 aba 13
3 abb 13

I want sql query for this
Posted

1 solution

If I understood your question correctly, you want to perform 2 queries that return 2 result sets that have the same fields. In your case, all you need is using the OR operator or the IN operator like this
SQL
select * from table_name where age=12 or age=13
-- or
select * from table_name where age IN (12, 13)

or you use the UNION operator[^] like this
SQL
select * from table_name where age=12
UNION
2 select * from table_name where age=13

The UNION operator is used to concatenate 2 result sets that have the same structure (same number of columns and similar data types in the same order). But in your case, the OR operator or the IN operator is enough.
 
Share this answer
 
v2

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