How to make a selection based on similar values ​​from multiple columns in sql

I have two tables with columns:

Genres  
  ID  
  genre

and

Adjectives
  ID
  adjective_title

I need to make a selection that returns matching values ​​from both columns of tables with syntax like.

For example, if ep were entered with like, the results would look like this:

result_column:
--------------
epiphonic -- (from genres table)
epic      -- (from adjectives table)

etc.,.

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

+3
source share
2 answers

try it

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 remove duplicates in each request, using UNION ALL for each.

+8
source

, , concat , :

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

Source: https://habr.com/ru/post/1719883/


All Articles