| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

06-30-09, 08:25
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 332
|
|
|
Query advice
|
|
Hi
I'm trying to write a query like:
Select datetime, A, B, C, D from schema.table where B=1 and B=2 and B=3 and B=4 and datetime=trunc(sysdate)-1
But I need the results to be sorted by B.
Would appreciate any advice?
Regards
Sheraz
|
|

06-30-09, 08:39
|
|
Registered User
|
|
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,407
|
|
>B=1 and B=2 and B=3 and B=4
returns no rows
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
|
|

06-30-09, 08:39
|
|
Registered User
|
|
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
|
|
|
|
Have you tried adding the "ORDER BY" option to your query?

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
|
|

06-30-09, 09:01
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 332
|
|
|
thanks
thanks. I think I mis-explained by concern.
I must select E and F when B=1 and G and H when B=2.
Also, if possible in the same query, I'd like to select E and F when B=3 and G and H when B=4.
|
|

06-30-09, 09:13
|
|
Registered User
|
|
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,407
|
|
If/when B=1, then by definition B can NOT equal 2 at same time (B=1 and when B=2) so returns no rows once again.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
|
|

06-30-09, 09:55
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 332
|
|
thanks I was just asking if it was possible to combine these conditions in one query something like nested queries, joins...etc I don't know.
|
|

06-30-09, 11:15
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 1,072
|
|
Through a UNION ALL?
Code:
select E as field1, F as field2
from table
where B=1
union all
select G as field1, H as field2
from table
where B=2
--=cf
|
|

06-30-09, 11:30
|
|
Registered User
|
|
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
|
|
Sql tutorial for beginners?
Quote:
|
Originally Posted by shajju
thanks I was just asking if it was possible to combine these conditions in one query something like nested queries, joins...etc I don't know.
|
Maybe you should spend some time reading an SQL tutorial.

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
|
|

07-01-09, 04:44
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 332
|
|
|
Thank you
Appreciate all the help guys. I too think a bit of reading is required on my part. It's just that I tend to fall asleep when doing so 
|
|

07-01-09, 11:49
|
|
Registered User
|
|
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,407
|
|
Select datetime, A, B, C, D from schema.table where B IN (1,2,3, 4) and datetime=trunc(sysdate)-1
ORDER by B
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
|
|

07-02-09, 08:49
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 332
|
|
Yep...that's what I did, thanks.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|