473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

OR in the WHERE Clause?

I am trying to create a system that will select candidates for a job
based on certain criteria (i.e. Supperted States)

The candidates are allowed to choose up to 5 supported states. The
problem comes when creating the query to pull the candidates out.

I can get it to work with only one supported state, no problem. But I
have no idea how to tell the DB to look through SupportedState1 OR
SupportedState2 OR SupportedState3 OR SupportedState4 OR
SupportedState5 to find the particular state that the job is in.

Does an OR operator exist; or at least some mechanism for achieving
this? Maybe there is a smarter way to implement this instead of 5
seperate fields for the supported states?

Thanks so much,
Alex

Jun 30 '06 #1
3 962
Alex (ia*******@gmail.com) writes:
I am trying to create a system that will select candidates for a job
based on certain criteria (i.e. Supperted States)

The candidates are allowed to choose up to 5 supported states. The
problem comes when creating the query to pull the candidates out.

I can get it to work with only one supported state, no problem. But I
have no idea how to tell the DB to look through SupportedState1 OR
SupportedState2 OR SupportedState3 OR SupportedState4 OR
SupportedState5 to find the particular state that the job is in.

Does an OR operator exist; or at least some mechanism for achieving
this? Maybe there is a smarter way to implement this instead of 5
seperate fields for the supported states?


There is an OR operator. But I have no clue how you should write the query
since I don't know your tables.

But if you have five columns for supported states, and you have the
possibility to redesign, do so. Make "supported states" table instead.
Then you may find that there is no reason to have a limit on five states,
at least not from the database point of view.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 30 '06 #2
Redesign your db, i.e instead of a table with the 5 supported states
columns , set up a lookup table , and then a table with 2. columns i.e
candidateId | SupportedStaeID |

--
----
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Alex" <ia*******@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
I am trying to create a system that will select candidates for a job
based on certain criteria (i.e. Supperted States)

The candidates are allowed to choose up to 5 supported states. The
problem comes when creating the query to pull the candidates out.

I can get it to work with only one supported state, no problem. But I
have no idea how to tell the DB to look through SupportedState1 OR
SupportedState2 OR SupportedState3 OR SupportedState4 OR
SupportedState5 to find the particular state that the job is in.

Does an OR operator exist; or at least some mechanism for achieving
this? Maybe there is a smarter way to implement this instead of 5
seperate fields for the supported states?

Thanks so much,
Alex

Jul 3 '06 #3
The WHERE clause does recognize the OR operator, as in:

WHERE SupportedState1 = 'CA' OR SupportedState2 = 'WA'

Like the others pointed out though, what you should do is look at
re-designing these tables. Ideally you should have a separate "supported
state" table related to the candidates table by the candidate table primary
key. This turns your queries into a simple inner join without all the
explicit "OR" logic, and also allows you to store as many states per
candidate as you wish. It also helps enforce referential integrity. So if
a candidate only has one or two supported states you won't waste all that
extra time and programming logic trying to determine this. Also if your
requirements change in the future, like if the number of supported states
suddenly jumps up to 10 per candidate, you won't have to re-design all of
your tables and queries.
Jul 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
2
by: aj70000 | last post by:
This is my query select ano,max(date),a_subject from MY_TAB where table_name='xyz' and ano=877 group by a_subject,ano order by a_subject ANO max(Date) A_Subject 877 2005-01-20...
7
by: JJ_377 | last post by:
Can someone tell me why SQL seems to ignore my order by clause? I tried to run through the debugger, but the debugger stops at the select statement line and then returns the result set; so, I have...
27
by: Chris, Master of All Things Insignificant | last post by:
I have come to greatly respect both Herfried & Cor's reponses and since the two conflicted, I wanted to get some clarification. My orginal post: Herfried, maybe your example here can get you to...
3
by: Sean Shanny | last post by:
To all, We are running postgresql 7.4.1 on an G5 with dual procs, OSX 10.3.3 server, 8GB mem, attached to a fully configured 3.5TB XRaid box via fibre channel. I think we have run into this...
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
25
by: metaperl.etc | last post by:
A very old thread: http://groups.google.com/group/comp.lang.python/browse_frm/thread/2c5022e2b7f05525/1542d2041257c47e?lnk=gst&q=for+else&rnum=9#1542d2041257c47e discusses the optional "else:"...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
6
by: jackal_on_work | last post by:
Hi Faculties, I have two queries which give me the same output. -- Query 1 SELECT prod.name, cat.name FROM products prod INNER JOIN categories cat ON prod.category_id = cat.id WHERE cat.id...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.