Solved

Multiple Values in A SELECT WHERE statement

Posted on 2007-11-30
7
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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://…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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