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.

 
Go Back  dBforums > Database Server Software > Oracle > Query advice

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-09, 08:25
shajju shajju is offline
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
Reply With Quote
  #2 (permalink)  
Old 06-30-09, 08:39
anacedent anacedent is offline
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.
Reply With Quote
  #3 (permalink)  
Old 06-30-09, 08:39
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool

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
Reply With Quote
  #4 (permalink)  
Old 06-30-09, 09:01
shajju shajju is offline
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.
Reply With Quote
  #5 (permalink)  
Old 06-30-09, 09:13
anacedent anacedent is offline
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.
Reply With Quote
  #6 (permalink)  
Old 06-30-09, 09:55
shajju shajju is offline
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.
Reply With Quote
  #7 (permalink)  
Old 06-30-09, 11:15
chuck_forbes chuck_forbes is offline
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
Reply With Quote
  #8 (permalink)  
Old 06-30-09, 11:30
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Wink 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
Reply With Quote
  #9 (permalink)  
Old 07-01-09, 04:44
shajju shajju is offline
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
Reply With Quote
  #10 (permalink)  
Old 07-01-09, 11:49
anacedent anacedent is offline
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.
Reply With Quote
  #11 (permalink)  
Old 07-02-09, 08:49
shajju shajju is offline
Registered User
 
Join Date: Aug 2008
Posts: 332
Yep...that's what I did, thanks.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On