Notices
The Basement Non-Honda/Acura discussion. Content should be tasteful and "primetime" safe.

anyone know SQL?

Thread Tools
 
Old Oct 27, 2004 | 05:29 PM
  #1  
ManInCamo's Avatar
ManInCamo
Thread Starter
Old School Crew
 
Joined: May 2000
Posts: 5,251
Likes: 0
Default anyone know SQL?

I need to find the description and weight that is less than 5, AND greater than 10. I can'tseem to do it with one command though, so I had to use:

select description, weight from product where weight < 5;

select description, weight from product where weight > 10;


how can I merge that into one command?
Reply
Old Oct 27, 2004 | 06:34 PM
  #2  
reno96teg's Avatar
reno96teg
Moderator
 
Joined: Dec 2000
Posts: 21,573
Likes: 0
Default

select description, weight from product where (weight < 5 OR weight > 10);
Reply
Old Oct 27, 2004 | 06:38 PM
  #3  
Andy's Avatar
Andy
Hybrid Forum Moderator
 
Joined: Mar 2000
Posts: 2,363
Likes: 0
From: Southwestern PA
Default

Your trying to find something that is less than 5 and greater than 10 at the same time? I can't tell you regardless of the SELECT statement, your never going to get any results. You can use AND and OR operators like reno stated though to combine them. I don't know if you need the () though.
__________________
Andy - Reinstated Hybrid Forum Moderator

'06 Subaru Legacy Spec B - Stock, for now
'98 Civic EX - CTR headlights and grill, Kosei K1's, for sale
'90 240SX - SR20DET that will never get installed, project car.
Reply
Old Oct 27, 2004 | 06:43 PM
  #4  
reno96teg's Avatar
reno96teg
Moderator
 
Joined: Dec 2000
Posts: 21,573
Likes: 0
Default

Originally Posted by Andy
I don't know if you need the () though.
not necessary in that instance, but i like doing that to make my queries easier to read.
Reply
Old Oct 27, 2004 | 06:48 PM
  #5  
flipped cracka's Avatar
flipped cracka
BOOM goes the dynamite!
 
Joined: Mar 2003
Posts: 27,571
Likes: 1
From: in a van down by the rive
Default

Originally Posted by reno96teg
select description, weight from product where (weight < 5 OR weight > 10);
yes, looks good to me. i wouldn't use the () though, but that's just me.
Reply
Old Oct 27, 2004 | 09:14 PM
  #6  
benjamin's Avatar
benjamin
Stuff and things.
 
Joined: Dec 2003
Posts: 1,972
Likes: 0
From: New York
Default

Originally Posted by flipped cracka
yes, looks good to me. i wouldn't use the () though, but that's just me.
I would. Even if the parser doesn't require it, the parentheses make the statement easier to read now and later.
Reply
Old Oct 27, 2004 | 09:16 PM
  #7  
benjamin's Avatar
benjamin
Stuff and things.
 
Joined: Dec 2003
Posts: 1,972
Likes: 0
From: New York
Default

Originally Posted by Andy
Your trying to find something that is less than 5 and greater than 10 at the same time? I can't tell you regardless of the SELECT statement, your never going to get any results. You can use AND and OR operators like reno stated though to combine them. I don't know if you need the () though.
I think he's trying to exclude items with a weight between 5 and 10 pounds.
Reply




All times are GMT -8. The time now is 12:23 AM.