Solved

Multiple Values in A SELECT WHERE statement

Posted on 2007-11-30
7
406 Views
Last Modified: 2012-06-27
Hi,

I need to select multiple values in a where statement, i.e.

SELECT * FROM COLORS where NAME='blue, green, red'

But this is only pulling the first two rows. Am I doing this right? I'm trying to get all records that match ONE of the potential values.
0
Comment
Question by:bsowards
  • 3
  • 2
  • 2
7 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20387123
SELECT * FROM COLORS WHERE NAME='blue' OR NAME='green' OR NAME='red'
0
 

Author Comment

by:bsowards
ID: 20387124
Correction, it is only pulling matches with the first value - which results in two rows of data returned.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20387126
basically you can use the OR operator to match just one of the values you are wanting to match, in this case, blue, green or red.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:bsowards
ID: 20387133
What I got that worked is below, using my actual query. It's not very elegant though - can anyone suggestion an improvement?

SELECT pagetitle FROM `modx_site_content` WHERE `parent`=17 OR `parent`=40 OR `parent`=18 OR `parent`=45 OR `parent`=46 OR `parent`=41 OR `parent`=44 OR `parent`=42 OR `parent`=43 OR `parent`=79 OR `parent`=80 OR `parent`=78 OR `parent`=83 OR `parent`=82 OR `parent`=84 OR `parent`=81 OR `parent`=72 OR `parent`=76 OR `parent`=77 OR `parent`=73 OR `parent`=75 OR `parent`=74 OR `parent`=69 OR `parent`=70 OR `parent`=71 OR `parent`=63 OR `parent`=67 OR `parent`=68 OR `parent`=64 OR `parent`=66 OR `parent`=65 OR `parent`= 122 OR `parent`= 121 OR `parent`= 124 OR `parent`= 123 OR `parent`= 125 OR `parent`= 131 OR `parent`=128 OR `parent`=127 OR `parent`=126 OR `parent`=130 OR `parent`=129 OR `parent`=114 OR `parent`=113 OR `parent`=117 OR `parent`=118 OR `parent`=116 OR `parent`=115 OR `parent`=120 OR `parent`=119 OR `parent`=132 OR `parent`=93 OR `parent`=91 OR `parent`=90 OR `parent`=89 OR `parent`=92 OR `parent`=106 OR `parent`=112 OR `parent`=108 OR `parent`=109 OR `parent`=107 OR `parent`=111 OR `parent`=110 OR `parent`=94 OR `parent`=97 OR `parent`=95 OR `parent`=98 OR `parent`=101 OR `parent`=99 OR `parent`=100 OR `parent`=96 OR `parent`=105 OR `parent`=104 OR `parent`=103 OR `parent`=102
0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 500 total points
ID: 20387140
try tjis
SELECT * FROM COLORS where NAME IN ('blue, green, red')
0
 

Author Closing Comment

by:bsowards
ID: 31412079
Just what I was looking for thanks!
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 20387172
Thank you
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now