Skip to content
Advertisement

Search data based on two columns SQL

I have a database table like this:

I need search from Id the Id’s that not have Tipo = Inventario and Create a new line with that data, I mean for example, RTOR-00261 and RTOR-0255 dont have INVENTARIO, I need to create new with the fields that there is in SUSTRATO. All data are in the same table

Final outptut like this:

I tried with:

Doesn’t work

Other:

Doesn’t work as well.

I need help with this – any ideas?

Advertisement

Answer

These two solutions work (you were very close):

With a Subquery:

With a left join:

DB Fiddle

Edit: I also think the question should be different. More like “How to select rows that don’t match criteria in the same table” or so. The question ‘search data based on two columns’ is way too broad, that could be answered with ‘WHERE … AND … ‘.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement