[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: QUICK HELP, two selects, maybe nested.
Corey Kaye writes:
> Looking though the docs. MySQL does not support nested selects but i'm looking for a way to speed up my PHP.
>
> This is what i have:
>
> CREATE TABLE departmentuser (
> userid int(10) unsigned zerofill default NULL,
> departmentid int(10) unsigned zerofill default NULL,
> KEY userid_departmentid(userid,departmentid)
> );
>
> What i need to do is select out of this table all the userid's that have a departmentid of 368 AND 142.
>
> What is the best way to do this?
>
> Currently i'm selecting all the users with 368 and running through a loop and checking to see if the returned list of userid also have 142. This takes about 20sec as this is a BIG list !
>
> PLEASE HELP !!!!
>
> PS I've never done it but can you use IF statements in MySQL ?
>
Would this query do what you need ??
SELECT userid from departmentuser where departmentid IN (142,368);
--
Consider taking our support. Visit : https://order.mysql.com
Regards,
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Sinisa Milivojevic <sinisa@xxxxxxxxx>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Fulltime Developer
/_/ /_/\_, /___/\___\_\___/ Larnaca, Cyprus
<___/ www.mysql.com
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <mysql-thread92831@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
This mailing list archive is a service of Copilot Consulting.