Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selected selection??

Status
Not open for further replies.

spiff2002

IS-IT--Management
Jan 31, 2003
40
I'm trying to select a gruop of items within a group
Suppose I have two tables.
A brand table (brandtable)
id Decsription
-- -----------
1 brandA
2 brandB
3 brandC

an Item table (itemtable)
id Description Brandid
-- ----------- -------
1 item1 1
2 item2 1
3 item3 2
4 item4 3
5 item5 3
6 item6 3
7 item7 3
8 item8 3

I need to run a select * from itemtable
but only select some items from brand3
like (if brandid = 3 then select itemtable.id>=4 and itemtable.id<=6)

and the result would be something like
id Description Brandid
-- ----------- -------
1 item1 1
2 item2 1
3 item3 2
4 item4 3
5 item5 3
6 item6 3
 
Unless I'm missing something, this should do it:

Select *
from ItemTable
Where BrandID = 3
and ID between 4 and 6
 
Something like this ?
select * from itemtable where brandid<>3 or id between 4 and 6

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I think I used wrong wording when I said

"but only select some items from brand3"

What I meant was:
Select all items from itemtable but when Brandid=3 then only select items which are (itemid>=4 and itemid<=6)

creating the output:

id Description Brandid
-- ----------- -------
1 item1 1
2 item2 1
3 item3 2
4 item4 3
5 item5 3
6 item6 3


 
How about

Select *
from ItemTable
Where BrandID <> 3
OR (BrandID = 3
and ID between 4 and 6)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top