Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multiple Values in A SELECT WHERE statement

Posted on 2007-11-30
7
Medium Priority
?
419 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

772 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