Problem with subqueries
hi, I have some sql code that I need to use with mysql it uses nested queries and since mysql doesn't implement them I would like to know how to do this. SELECT * FROM apartamentos WHERE vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... WHERE Referencia NOT IN ( SELECT Referencia FROM historico_clientes WHERE NumCliente=$id) Best Regards, Luis Rodrigues - 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
Re: Problem with subqueries
MySQL does not support sub-queries. Take a look at JOINS (http://www.mysql.com/doc/J/O/JOIN.html) - Original Message - From: Luis Rodrigues [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, July 31, 2002 6:03 AM Subject: Problem with subqueries hi, I have some sql code that I need to use with mysql it uses nested queries and since mysql doesn't implement them I would like to know how to do this. SELECT * FROM apartamentos WHERE vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... WHERE Referencia NOT IN ( SELECT Referencia FROM historico_clientes WHERE NumCliente=$id) Best Regards, Luis Rodrigues - 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 - 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
Re: Problem with subqueries
On Wed, 2002-07-31 at 12:03, Luis Rodrigues wrote: hi, I have some sql code that I need to use with mysql it uses nested queries and since mysql doesn't implement them I would like to know how to do this. SELECT * FROM apartamentos WHERE vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... WHERE Referencia NOT IN ( SELECT Referencia FROM historico_clientes WHERE NumCliente=$id) snip It will require something like: SELECT a.* FROM apartamentos a LEFT JOIN historico_clientes h ON a.Referencia = h.Referencia AND h.NumCliente=$id WHERE h.Referencia IS NULL AND vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... == Martin - 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
Re: Problem with subqueries
Thanks. On 31 Jul 2002, Martin Waite wrote: On Wed, 2002-07-31 at 12:03, Luis Rodrigues wrote: hi, I have some sql code that I need to use with mysql it uses nested queries and since mysql doesn't implement them I would like to know how to do this. SELECT * FROM apartamentos WHERE vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... WHERE Referencia NOT IN ( SELECT Referencia FROM historico_clientes WHERE NumCliente=$id) snip It will require something like: SELECT a.* FROM apartamentos a LEFT JOIN historico_clientes h ON a.Referencia = h.Referencia AND h.NumCliente=$id WHERE h.Referencia IS NULL AND vendido=0 AND Concelho=$row[ConcelhoP] AND Localidade LIKE '$row[LocalidadeP]' ... == Martin - 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 - 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