views:

104

answers:

2

I have two tables with columns:

Genres: ID, genre
Adjectives: ID, adjective_title

I need to do a select that returns the matching values from both tables columns with the 'like' syntax.

For example if "ep" was the value entered using 'like' the results would look like:

result_column:

epiphonic (from genres table)

epic (from adjectives table)

etc . . .

I'm pretty sure I need to use a subquery to return the results.

+5  A: 

try this

SELECT genre AS result
FROM genres
WHERE genre LIKE '%ep%'
UNION
SELECT adjective_title AS result
FROM 
  adjectives
WHERE adjective_title LIKE '%ep%'

The union will eliminate duplicates in each query use UNION ALL for each.

John Nolan
That's awesome! Thanks!
Buffernet
A: 

You can do this without sub-selects, but it won't be quick on large tables, by using concat to build the string you use the like operator on:

select g.ID, g.genre, a.adjective_title from Genres g, Adjectives a where
concat(g.genre, a.adjective_title) like '%epic%'
rsp