Solved

Multiple Values in A SELECT WHERE statement

Posted on 2007-11-30
7
409 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
Creating and Managing Databases with phpMyAdmin in cPanel.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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