Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Union and Union All :

There are two tables, A and B.
Table A has columns, x1, x2, x3 and table B has columns x1, x2, x3.
They have same rows, a,b,c,d,e.
How can I retrieve all the distict rows from both the tables?
Union or Union all ? why ?


Store proc :

If I have multiple rows returned by a proc and I need to work on each rows.
how can i do that ?
Posted

1 solution

Regarding your 1st question -

UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not.


So, you will need to use UNION to remove duplicate records.

Regarding your 2nd question, it totally depends on what do you want to work on the each row. This can be done by
1. Using function(s)
2. Using Cursors.
 
Share this answer
 
Comments
Swap9 15-Nov-13 8:29am    
How can i scan through all the returned rows using functions ?
Ashish_Agrawal 15-Nov-13 8:41am    
Could you please tell me what do you want to do with each row. If you need to do some processing on one column, you can create a functions. Then you can call the function in your select query. Something like this

SELECT Col1, DoSomeProcessing(Col2) as Col2 FROM table1.

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