MySQL selects one field from a table. The WHERE clause is on several lines.

I tried to find the answer, but still could not .. The table looks like this:

id, keyword, value
1 display 15.6
1 harddrive 320
1 ram 3

So I need something like this .. Select an identifier from this table, where (keyword="display" and value="15.6") AND (keyword="harddrive" and value="320") There is also a possibility that there will be 3 or 4 such keyword conditions that should lead to the return of one identifier (one row)

Something seems to be related to UNION, but I haven't used it before, so I can't figure it out

Thanks in advance

+3
source share
2 answers

. - .

SELECT id
FROM your_table
WHERE 
(keyword="display" and value="15.6") OR (keyword="harddrive" and value="320")
GROUP BY id
HAVING COUNT(*) = 2

, , , . (, PK id, keyword)

+3
SELECT DISTINCT id FROM table
WHERE 
(keyword="display" and value=15.6) OR (keyword="harddrive" and value=320)
0

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


All Articles