| Author |
Topic |
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-05-31 : 14:56:31
|
| How can I do that in one sentence:SELECT * FROM qqq WHERE condition=1SELECT * FROM www WHERE condition=1 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-05-31 : 14:58:55
|
Select * From qqq where condition=1UNION ALLSelect * From www where condition=1Corey Secret Service Agent: Mr. President, you're urinating on me.President Lyndon Johnson: I know I am. It's my prerogative. |
 |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-05-31 : 15:02:16
|
| Hum, not that way because with UNION you need to have the same number of rows |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
1fred
Posting Yak Master
158 Posts |
Posted - 2005-05-31 : 15:22:13
|
| And why do you need data that do not have the same column name and number to be returned in the same dataset?If one is have 4 column and the other 5, you can add blank field.select c1, c2, c3, c4, '' as c5 from qqq where condition = 1union select c1, c2, c3, c4, c5 from www where condition = 1Maybe if you can tell us more about what you want to do we can help you finding the right solution. |
 |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-05-31 : 15:22:34
|
| Good one but not enough for meThen how can you figure out where come from each rowDoes something like that exist:SELECT * FROM qqq INNER JOIN (SELECT * FROM www WHERE condition=1) WHERE condition=2 |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-05-31 : 15:26:32
|
| scrap -- how about you actually tell us what you are trying to do. It's kind of hard to guess. An example with what data you have and what you want to return with some logic to describe it would be helpful.- Jeff |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-05-31 : 15:32:46
|
| [code]SELECT 'myTable00' AS Source, Col1, Col2, Col3 FROM myTable00UNION ALLSELECT 'myTable99' AS Source, Col1, Col2, Null AS Col3 FROM myTable99[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-05-31 : 15:33:14
|
quote: Originally posted by jsmith8858 scrap -- how about you actually tell us what you are trying to do. It's kind of hard to guess. An example with what data you have and what you want to return with some logic to describe it would be helpful.- Jeff
Have you seen my Hint?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-05-31 : 15:33:53
|
as for distinguishing...select 'qqq' as src, c1, c2, c3, c4, '' as c5 from qqq where condition = 1union select 'www' as src, c1, c2, c3, c4, c5 from www where condition = 1Corey Secret Service Agent: Mr. President, you're urinating on me.President Lyndon Johnson: I know I am. It's my prerogative. |
 |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-05-31 : 15:36:04
|
| How can you insert a view in Select * from QQQ where Condition =2When I insert the View, everything screw upSorry I do not want to show the code.I know it makes it hard to debug and I guess if there were a solution somebody would have already wrote it. |
 |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-05-31 : 15:44:32
|
| Thanx everyone especially to Seventhnight, 1fred and X002548. I'm now gone for a few test! |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-05-31 : 15:56:43
|
as a note when you get back... Brett's hint is not to get to your code. You develop an example that mimics the exact behavior you are trying to build in you production code. Then we help solve the example. You then take that solution and apply it to your production code.[Trying not to sound arrogant]We don't need your code, especially if we are helping you with it. [/Trying not to sound arrogant]Good luck with it! Corey Secret Service Agent: Mr. President, you're urinating on me.President Lyndon Johnson: I know I am. It's my prerogative. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-05-31 : 16:07:02
|
quote: Originally posted by Seventhnight [Trying not to sound arrogant]We don't need your code, especially if we are helping you with it. [/Trying not to sound arrogant]
Thanks for the chuckle....Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|