Bluehost.com Web Hosting $6.95

Can this basic query be simplified?

This is a discussion on Can this basic query be simplified? within the MySQL Database forums, part of the Database Forums category; SELECT * FROM table WHERE userID='1' OR userID='5' OR userID='9' OR userID='27' OR userID='92' ORDER BY ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-12-2007
Ciaran
 
Posts: n/a
Default Can this basic query be simplified?

SELECT * FROM table WHERE userID='1' OR userID='5' OR userID='9' OR
userID='27' OR userID='92' ORDER BY rand() LIMIT 30

Reply With Quote
  #2 (permalink)  
Old 03-12-2007
Captain Paralytic
 
Posts: n/a
Default Re: Can this basic query be simplified?

On 12 Mar, 10:47, "Ciaran" <cronok...@hotmail.com> wrote:
> SELECT * FROM table WHERE userID='1' OR userID='5' OR userID='9' OR
> userID='27' OR userID='92' ORDER BY rand() LIMIT 30


SELECT
*
FROM `table`
WHERE userID IN ('1', '5', '9', '27', '92')
ORDER BY rand()
LIMIT 30

Reply With Quote
  #3 (permalink)  
Old 03-12-2007
Ciaran
 
Posts: n/a
Default Re: Can this basic query be simplified?

Brilliant! That's much better, thanks a lot!
Ciarán

Reply With Quote
  #4 (permalink)  
Old 03-12-2007
Brian Wakem
 
Posts: n/a
Default Re: Can this basic query be simplified?

Captain Paralytic wrote:

> On 12 Mar, 10:47, "Ciaran" <cronok...@hotmail.com> wrote:
>> SELECT * FROM table WHERE userID='1' OR userID='5' OR userID='9' OR
>> userID='27' OR userID='92' ORDER BY rand() LIMIT 30

>
> SELECT
> *
> FROM `table`
> WHERE userID IN ('1', '5', '9', '27', '92')
> ORDER BY rand()
> LIMIT 30



You can simplify that even further by removing the '' around the numbers,
they are not needed.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Reply With Quote
  #5 (permalink)  
Old 03-12-2007
Rik
 
Posts: n/a
Default Re: Can this basic query be simplified?

Ciaran <cronoklee@hotmail.com> wrote:

> SELECT * FROM table WHERE userID='1' OR userID='5' OR userID='9'OR
> userID='27' OR userID='92' ORDER BY rand() LIMIT 30


SELECT * FROM table WHERE userID IN (1,5,9,27,92) ORDER BY RAND() LIMIT 30
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Reply With Quote
  #6 (permalink)  
Old 03-12-2007
Rik
 
Posts: n/a
Default Re: Can this basic query be simplified?

D'OH!
Didn't see it was already ansered..
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Reply With Quote
Reply
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

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




All times are GMT +1. The time now is 05:19 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0