Guldstrand Posted July 21, 2021 Share Posted July 21, 2021 How can I do a keyword search in two completely different tables? In one table you search for "movie title" and in the other table "actor name". Quote Link to comment Share on other sites More sharing options...
kicken Posted July 21, 2021 Share Posted July 21, 2021 You can use a UNION to combine two queries into a single result set. SELECT 'movie' as type, id, title as label FROM movies WHERE title like 'blah%' UNION ALL SELECT 'actor' as type, id, name as label FROM actors WHERE name like 'blah%' Each query must return the same number and type of columns. If necessary, you can use literal values / NULL to fill out columns that might be irrelevant in one query or the other. Quote Link to comment Share on other sites More sharing options...
Guldstrand Posted July 22, 2021 Author Share Posted July 22, 2021 Thanks for your reply. I can't use UNION cause the tables or different, as i wrote in my first post. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 22, 2021 Share Posted July 22, 2021 44 minutes ago, Guldstrand said: I can't use UNION cause the tables or different, as i wrote in my first post. BULLSH*T. If you actually read @kicken's reply you will see he is using two different tables in his example. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.