Get the result of a query and through that result make a like to another table

1

Good morning. I need to mix both queries in one

SELECT nombre_categoria from tablacategorias where id_categoria=1;
select * from videos A where A.categorias;

What I try is: In the "tablacategorias" I want you to return the name of the category according to the id that happened to you. Once I have the "category name" I want to get from the "videos" table all the videos that have that category.

I need it to be through LIKE, since a video can have more than one category. In my case the categories go in the same field separated by commas. Example: Drama, comedy, action

The result would be something like this:

select * from videos A where A.categorias like '%(SELECT nombre_categoria from tablacategorias where id_categoria=1)%'
    
asked by Alonso 31.07.2017 в 10:31
source

1 answer

3

You can join it into one by doing a JOIN where the condition is like , it would be something like this:

select A.* from videos
join tablacategoria tCat on A.categorias like 
'%' + tCat.nombre_categoria + '%' 
where tCat.id_categoria=1
    
answered by 31.07.2017 / 10:41
source