Re: A MySQL Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
Hi gang:

I just interviewed for a job teaching at the local college (imagine me taking minds of mush and molding them to the world according to tedd -- frightening huh?)

In any event, the interviewer asked me how long I've been using MySQL and I replied several years. After which she asked a single question, which was "What does EXIST mean?"

There is no 'Exist' keyword in sql, it's 'EXISTS'. Everyone seems to know the "drop table if exists" syntax but that's not the right one they are after (and it's non-standard sql).

There is an 'Exists' keyword for subselects. Instead of doing an IN query, you can do an 'exists' query - but it's use is very different.

It returns true if any row in the subquery exists or false if none exist. The idea is instead of:

select * from accounts where company_id in (select company_id from companies where name='X');

you do

select * from company where company_id exists (select company_id from companies where name='X');

the subselect checks the company table for the id, if it exists, the outer query runs. It does not matter what company_id is returned from the subquery, just that at least 1 does return.

I've never used this anywhere myself because I usually care what id's are returned from the subquery.

(Yes, that's from the top of my head :P but here's doc's to help).

http://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html
http://www.postgresql.org/docs/8.3/static/functions-subquery.html

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux