3

I have two tables with columns:

Genres  
  ID  
  genre

and

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.

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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%'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.