Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mkgmahi
Starting Member
24 Posts |
Posted - 2011-12-19 : 00:17:55
|
| I have a problem with the union query. How should i add a column in a union query without affecting the rowsFor Example: select a from x union select b from yBoth queries have similar records so they unite and show me without dups.Butselect a, ' ' status from x union select, status from YWherein first query we give comment as we dont have status in it and in the second query we add the status but this time it shows me additional records which is not tallying with my previous no of rows.Hope u guys can understand my explanationPlease let me know any suggestions..it would be great |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-19 : 00:22:14
|
[code]select a, isnull(y.status, '') as statusfrom( select a from x union select b from y) zleft join y on z.a = y.b[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
mkgmahi
Starting Member
24 Posts |
Posted - 2011-12-19 : 00:41:49
|
| I tried but i am unable to get the result. selectt.type,t.qty,' ' statusfrom type tunionselectt.storet.qty,i.statusfromtype t,inventry iPlease let me know for the above one. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 01:09:43
|
| if you want to tally number of rows, then you need to determine how you're going to merge comments with statuses. do you've common column on basis of which you can merge? else how would you determine which comment gets merged with which status?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-19 : 01:54:35
|
quote: Originally posted by mkgmahi I tried but i am unable to get the result. selectt.type,t.qty,' ' statusfrom type tunionselectt.storet.qty,i.statusfromtype t,inventry iPlease let me know for the above one.
Is that the query that you tried ? Have you tried with the query that i posted ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
mkgmahi
Starting Member
24 Posts |
Posted - 2011-12-19 : 07:03:35
|
| sorry for late reply... I tried it but i am not getting the result |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 10:48:01
|
quote: Originally posted by mkgmahi sorry for late reply... I tried it but i am not getting the result
did you read my question? any answers...------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|