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!

Query Multiple Fields 1

Status
Not open for further replies.

TamedTech

IS-IT--Management
May 3, 2005
998
GB
Hi Guys,

I've got a client with an anoyance in thier database, basicly they have a list of books in the database, and in the books table there are 3 fields for catagory, as a book can belong to 3 catagories at any one time.

What i want to do is search for a value that could exist in any field and then use that to output a list for each catagory.

Is there an 'OR' statement i can use after me WHERE to do this.

So i.e.

SELECT * FROM books WHERE catagory_1 = 1 OR catagory_2 = 1 OR catagory_3 = 1

or somthing to that effect? this way i can search for the same value in all three fields.

Thanks,

Rob
 
something to that effect? yes :)

in fact, exactly like you had it --

WHERE catagory_1 = 1 OR catagory_2 = 1 OR catagory_3 = 1

there is also another way to do it --

WHERE 1 IN (catagory_1, catagory_2, catagory_3)

r937.com | rudy.ca
 
Thanks buddy,

It's always helpfull to have an SQL Consultant knocking around lol.

I'll use the latter i think as its slightly neater.

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top