Re: one more mysql question
| From: | Sebastian | Date: | Fri, 12 Aug 2005 23:41:06 +0000 |
| Subject: | Re: one more mysql question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-220540@lists.php.net to get a copy of this message | ||
afan@afan.net wrote:
I tried this one: SELECT trans_no FROM orders WHERE trans_no IN ( SELECT trans_no FROM special_orders ) but gives me an error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT trans_no FROM special_orders )' at line 5 ??? Philip Hallstrom wrote:try this (untested): SELECT * FROM trans_no LEFT JOIN special_orders ON (trans_no.id = special_orders.id) WHERE special_orders.id IS NULL; just change id to the primary key... -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.10.8/71 - Release Date: 8/12/2005I apology for mysql question posted here, but, as I said once, I like you guys more! :) have two tables: orders and special_orders. foreign key is trans_no. I can't figure it out how to create a query that pulls orders from the "orders" tables that are NOT in "special_orders" table?I can never remember the syntax, but you want to LEFT JOIN the tables and then only return rows where the resulting special_orders column is NULL. something like this (most likely wrong syntax): SELECT o.trans_no, s.trans_no FROM orders o LEFT JOIN special_orders s ON o.trans_no = s.trans_no WHERE s.trans_no IS NULL But that should get you started... -philip