Bring Select values where both MYSQL match

0

I have the following

SELECT * FROM metadatas WHERE value IN ('Monumento', 'Arquitectura')

After making that query, it brings me several results, but I need to bring where both coincide. The result would be the following:

id - name - value

1 - Church - Architecture

1 - church - Monument

2 - Minimalist house - Architecture

The result I'm looking for is:

id - name - value

1 - Church - Architecture

1 - church - Monument

Because Minimalist House does not have a Monument value.

    
asked by Arielperez 21.09.2018 в 17:40
source

1 answer

0

first you have to validate that there are two records for each NAME, and the last you place the same validation that you used.

SELECT * FROM metadatas2 
WHERE ID IN (SELECT ID FROM 
               (SELECT ID, NAME, COUNT(*) CANT FROM metadatas2
                GROUP BY ID,NAME)A
             WHERE CANT=2) 
AND  value IN ('Monumento', 'Arquitectura')

I hope it serves you Greetings!

    
answered by 21.09.2018 в 18:35