Re: WHERE IN SYNTAX
My mistake. I failed to mention that there are two tables, bar and baz. And, I found the answer to my question. Thanks everybody. On 12/2/02 5:52 PM, Adolfo Bello [EMAIL PROTECTED] wrote: Isn't this sort of impossible? You are asking for something like a set which contains as an element the set itself WHERE fooId IN (fooId) Adolfo -Original Message- From: Peter Abilla [mailto:[EMAIL PROTECTED]] Sent: Monday, December 02, 2002 1:43 PM To: [EMAIL PROTECTED] Subject: sql:WHERE IN SYNTAX Question about SQL WHERE IN syntax: I know that something like this is fine to do: (1) SELECT foo FROM bar WHERE fooID in ('1','2') In the example above, the parenthesis includes the itemized fooID's. But, I want to do a similar thing where instead of the actual fooID's in the WHERE IN clause, I reference a column that contains the fooID's, like: (2) SELECT foo FROM bar WHERE fooID in (bar.fooID) In this example, I have the table 'bar' and the column 'fooID'. Is (2) possible? If not, what other strategies are there? Please help. PSA - 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 - 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: WHERE IN SYNTAX
Isn't this sort of impossible? You are asking for something like a set which contains as an element the set itself WHERE fooId IN (fooId) Adolfo -Original Message- From: Peter Abilla [mailto:[EMAIL PROTECTED]] Sent: Monday, December 02, 2002 1:43 PM To: [EMAIL PROTECTED] Subject: sql:WHERE IN SYNTAX Question about SQL WHERE IN syntax: I know that something like this is fine to do: (1) SELECT foo FROM bar WHERE fooID in ('1','2') In the example above, the parenthesis includes the itemized fooID's. But, I want to do a similar thing where instead of the actual fooID's in the WHERE IN clause, I reference a column that contains the fooID's, like: (2) SELECT foo FROM bar WHERE fooID in (bar.fooID) In this example, I have the table 'bar' and the column 'fooID'. Is (2) possible? If not, what other strategies are there? Please help. PSA - 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: WHERE OR Syntax
Put parentheses around the ..OR.. part (between WHERE and AND) - AND precedes OR so Also, use 'IN' instead of a series of 'OR' - this will make the query a lot faster. e.g. listings.Area IN ('19','24','25',...) Vadim. JD Daniels wrote: I have this query built from a web form. The form will add to the query depending on what search criteria has been chosen. what happens is if they choose the criteria in the query below, it stops comparing the other criteria such as listed date and price range. Also the = operator does not return any results, and the = operator returns a syntax error at the . I am hopelessly confused. SELECT listings.lid,listings.Price,Area.Area,listings.Description,listings.Sold,lis tings.MLS_Number FROM listings LEFT JOIN Companies ON (listings.cid=Companies.cid) LEFT JOIN Area ON (listings.Area=Area.aid) LEFT JOIN rid ON (listings.rid=rid.rid) LEFT JOIN Property_Type ON (listings.Property_Type=Property_Type.ptid) LEFT JOIN Property_Style ON (listings.Property_Style=Property_Style.psid) WHERE listings.Area = '19' or listings.Area='25' or listings.Area='24' or listings.Area='32' or listings.Area='33' or listings.Area='28' or listings.Area='38' or listings.Area='39' or listings.Area='34' or listings.Area='20' or listings.Area='18' or listings.Area='22' or listings.Area='27' or listings.Area='17' or listings.Area='23' or listings.Area='29' or listings.Area='31' or listings.Area='37' or listings.Area='35' or listings.Area='36' AND TO_DAYS(NOW()) - TO_DAYS(Listed) 7 AND Price75000 It seems as soon as it hits the first OR condition, it ignores the AND condition. I was hoping the brackets would help, but it doesn't seem to matter. It works fine as long as I stick to AND. The numbers are the id for area types in another table that link to the listings table. How else can I check for a number of different area types and still further narrow the search down with other criteria? JD Daniels - 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