Re: Getting around 2 queries
Scott Haneda [EMAIL PROTECTED] wrote: I currently run this, which is 2 hits to the database. Select serial from blacklist where serial = '23' Select serial from seriallist where serial = '23' I only desire to know if either of the 2 has at least one row, I am only testing for existence here. Is there some way I can get around 2 queries and do this as one? Use UNION: http://www.mysql.com/doc/en/UNION.html -- For technical support contracts, goto https://order.mysql.com/?ref=ensita This email is sponsored by Ensita.net http://www.ensita.net/ __ ___ ___ __ / |/ /_ __/ __/ __ \/ /Egor Egorov / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net ___/ www.mysql.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: Getting around 2 queries
One option would be to 'union' the two queries (assuming the columns are the same type and length), allowing you to run one query string: Select serial from blacklist where serial = x Union Select serial from seriallist where serial = x Would return 1 or 2 rows, depending on whether rows are found in one table or both. You wouldn't know which table though (but from your message, I guess that is unimportant). I suppose there are a number of things you could do, really... Regards, Matt -Original Message- From: Scott Haneda [mailto:[EMAIL PROTECTED] Sent: 30 March 2004 07:39 To: MySql Subject: Getting around 2 queries I currently run this, which is 2 hits to the database. Select serial from blacklist where serial = '23' Select serial from seriallist where serial = '23' I only desire to know if either of the 2 has at least one row, I am only testing for existence here. Is there some way I can get around 2 queries and do this as one? -- - Scott HanedaTel: 415.898.2602 http://www.newgeo.com Fax: 313.557.5052 [EMAIL PROTECTED]Novato, CA U.S.A. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: Getting around 2 queries
Matt Chatterley wrote: One option would be to 'union' the two queries (assuming the columns are the same type and length), allowing you to run one query string: Select serial from blacklist where serial = x Union Select serial from seriallist where serial = x Would return 1 or 2 rows, depending on whether rows are found in one table or both. You wouldn't know which table though (but from your message, I guess that is unimportant). If you needed to know which table it came from, you could just expand this query a little: Select serial,'blacklist ' as Tablename from blacklist where serial = x Union Select serial,'seriallist' as Tablename from seriallist where serial = x -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Getting around 2 queries
I currently run this, which is 2 hits to the database. Select serial from blacklist where serial = '23' Select serial from seriallist where serial = '23' I only desire to know if either of the 2 has at least one row, I am only testing for existence here. Is there some way I can get around 2 queries and do this as one? -- - Scott HanedaTel: 415.898.2602 http://www.newgeo.com Fax: 313.557.5052 [EMAIL PROTECTED]Novato, CA U.S.A. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]