TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-13-2008, 02:18 PM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default SELECT statement -- list of fields in WHERE clause

Hi --

Can the list of fields in the WHERE clause of the following SELECT statement be written more efficiently? I used to use a program with an INLIST() option in which several fields could just be listed: WHERE INLIST(fieldname,"value1","value2",etc.) Can't find anything in MySQL, but then I don't have much experience...Thanks for any help!

Dave

Code:
select distinct coursetitle, statecourse, localcourse, semester, section, teachername
   from mytable
   where (semester = "0" or semester = "1") 
         and coursetitle is not null 
         and (statecourse = "1021X" or
              statecourse = "2020X" or
              statecourse = "2023X" or
              statecourse = "2024X" or
              statecourse = "2030X" or
              statecourse = "3010X" or
              statecourse = "3020X" or
              statecourse = "3038X" or
              statecourse = "3050X" or
              statecourse = "3060X" or
              statecourse = "4021X" or
              statecourse = "4024X" or
              statecourse = "4052X"
             )
   order by statecourse;
Dave is offline  
Reply With Quote
Old 09-13-2008, 03:08 PM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

you probably mean...

Code:
SELECT ... FROM tbl WHERE field_name IN('value1', 'value 2'[, ...])
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
ETbyrne (09-13-2008)
Old 09-13-2008, 03:32 PM   #3 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

I really need to study up on my SQL statements...
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
The Following User Says Thank You to ETbyrne For This Useful Post:
Dave (09-14-2008)
Old 09-14-2008, 01:20 AM   #4 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Exactly what the doctor ordered!

Thank you,
Dave
Dave is offline  
Reply With Quote
Old 09-16-2008, 11:16 AM   #5 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

And you should remember to use two eaqual "==" when comparing variables.... or else it will asign.

i fall for that one myself time to times.

Oh sorry. Didnīt see that it was in the SQL. Then itīs fine i guess.
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.

Last edited by EyeDentify : 09-16-2008 at 11:18 AM. Reason: my bad
EyeDentify is offline  
Reply With Quote
The Following User Says Thank You to EyeDentify For This Useful Post:
Dave (09-16-2008)
Old 09-16-2008, 07:13 PM   #6 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

A good thing to ALWAYS be aware of, though. It has tripped me up more than once, and, unfortunately, I'm sure it will in the future. I need a wall poster of [...can't make up my mind...Pam Anderson?..Sarah Palin..?..Satan?...] with the "==" rule plastered underneath!

Thanks,
Dave
Dave is offline  
Reply With Quote
Old 09-17-2008, 01:54 AM   #7 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Quote:
I need a wall poster of [...can't make up my mind...Pam Anderson?..Sarah Palin..?..Satan?...]
How about Bill Clinton? lol
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-17-2008, 11:36 AM   #8 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

No, Bill Clinton's photo would appear over the "is-is" rule, not the "==" rule.
Dave is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:15 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design