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 |
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2014-04-02 : 07:19:43
|
Hi I have query like, SELECT C1, C2 FROM T1 Where C3='MyVal' UNION ALL SELECT C1, C2 FROM T2 Where C3='MyVal'there is some possibility like - C3='MyVal' not in both tables T1, T2 - C3='MyVal' May present in any one table - C3='MyVal' may present in both tables.ThanksSubha |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2014-04-02 : 07:59:57
|
quote: Originally posted by subhaoviya Hi I have query like, SELECT C1, C2 FROM T1 Where C3='MyVal' UNION ALL SELECT C1, C2 FROM T2 Where C3='MyVal'there is some possibility like - C3='MyVal' not in both tables T1, T2 - C3='MyVal' May present in any one table - C3='MyVal' may present in both tables.ThanksSubha
Please give us examples with all possibilities over the 2 tables AND the wanted result in relation to the example data. Too old to Rock'n'Roll too young to die. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-04-02 : 11:26:33
|
quote: Originally posted by subhaoviya Hi I have query like, SELECT C1, C2 FROM T1 Where C3='MyVal' UNION ALL SELECT C1, C2 FROM T2 Where C3='MyVal'there is some possibility like - C3='MyVal' not in both tables T1, T2 - C3='MyVal' May present in any one table - C3='MyVal' may present in both tables.ThanksSubha
Why do you want to avoid UNION ALL? What issue are you trying to solve? Do you want the same results as a UNION ALL, but without using a UNION ALL? |
|
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2014-04-04 : 08:01:00
|
Hi, Sorry for late reply, I want to avoid union functions due to performance issue, because both table having million of records. I have resolved it by using dynamic SQL. just check the existence of value in both tables then for condition.then executed the query using join function.thankssubha |
|
|
|
|
|
|
|