Need a MySQL query for selecting from a table storing key value pairs

后端 未结 2 1592
后悔当初
后悔当初 2020-12-10 17:47

I need to store few items and its properties in form of a key value pairs in the database (mySQL). I am planning to do it as following.

I\'ll use two tables it

2条回答
  •  情歌与酒
    2020-12-10 18:20

    Here is an example query:

    SELECT
      itemName
    FROM
      items i,
    JOIN
      item_properties effect
      ON i.itemId = effect.itemId AND effect.property = 'effect'
    JOIN
      item_properties consumption
      ON i.itemId = consumption.itemId AND consumption.property = 'consumption'
    
    WHERE effect.value = 'cooling' AND consumption.value = 'efficient';
    

    I'll leave the oR query as something you can try yourself. It's simply adding more tables and using OR instead of AND in the WHERE.

提交回复
热议问题