Tim,
Tuesday, February 26, 2002, 4:20:46 AM, you wrote:

TP> Hi, 

TP> I am trying to make a database-neutral application.
TP> What is the MySQL idiom to replace the Postgres EXISTS function?

TP> I have two tables:

 
TP> mysql> select * from groupcapability;
TP> +----+--------------+------------+
TP> | id | melati_group | capability |
TP> +----+--------------+------------+
TP> |  0 |            0 |          0 |
TP> +----+--------------+------------+
 
TP> mysql> select * from groupmembership;
TP> +----+------+--------------+
TP> | id | user | melati_group |
TP> +----+------+--------------+
TP> |  0 |    1 |            0 |
TP> +----+------+--------------+

TP> In Postgres the following query works:

TP> SELECT * FROM groupmembership WHERE "user"  =  1  AND 
TP> EXISTS (
TP>    SELECT groupcapability."melati_group" , capability 
TP>      FROM groupcapability, groupmembership 
TP>           WHERE 
TP>            groupcapability."melati_group" = groupmembership."melati_group" 
TP>            AND 
TP>               capability = 0 );

TP> How should this be written in MySQL?

TP> (NB I have had to use melati_group instead of group due to MySQL objecting to 
TP> the keyword group.)

MySQL currently doesn't support sub-selects.
Take a look at JOIN statement and a temporary tables usage.
You can find info about it in the manual:
    http://www.mysql.com/doc/J/O/JOIN.html
    http://www.mysql.com/doc/A/N/ANSI_diff_Sub-selects.html
    http://www.mysql.com/doc/C/R/CREATE_TABLE.html

TP> tia
TP> timp





-- 
For technical support contracts, goto https://order.mysql.com/
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Egor Egorov
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   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 <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to