Do a query only if there are no results on previous query

Posted by yes123 on Stack Overflow See other posts from Stack Overflow or by yes123
Published on 2010-12-26T20:40:22Z Indexed on 2010/12/26 21:53 UTC
Read the original article Hit count: 311

Filed under:
|
|
|
|

Hi guys:

I do this query(1):

(1)SELECT * FROM t1 WHERE title LIKE 'key%' LIMIT 1

I need to do a second(2) query only if this previous query has no results

(2)SELECT * FROM t1 WHERE title LIKE '%key%' LIMIT 1

basically i need only 1 row who got the most close title to my key.

Atm i am using an UNION query with a custom field to order it and a LIMIT 1. Problem is I don't want to do the others query if already the first made the result.

Thanks

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql