Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query combined column values

Tags:

sql

mysql

I'm really not sure how to title this question... Imagine that we have a table looking like this:

object | attribute | value
------------------------------
   7     country     Germany
   7     position    12
   7     points      12
   8     country     Germany
   8     position    10
   8     points      3

Now I want to select all object identifiers that has country germany and position 12 or 5

I have no idea how to write this query, is it possible?

like image 699
xCander Avatar asked Mar 06 '26 15:03

xCander


1 Answers

Join as many times as you need additional query options:

SELECT t1.object
FROM table t1
    INNER JOIN table t2 ON t1.object = t2.object
WHERE t1.attribute = 'country' AND t1.value = 'Germany'
    AND t2.attribute = 'position' AND t2.value IN (12,5)
like image 183
Richard Avatar answered Mar 09 '26 03:03

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!