Solved

Multiple Values in A SELECT WHERE statement

Posted on 2007-11-30
7
408 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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