MySQL Query for select row with other way

I know to fetch the query but I have difficulties fetching in an advanced way or my requirement needs, my database is designed on the below structure, and I want to fetch the column value based on column type; like for Mango = 50, Banana = 20, etc.

ID | type    | value | key
-----------------------------------
1  | Mango   | 50    | AP123
2  | Banana  | 20    | AP123
3  | Apple   | 30    | AP123

In a simple way we can use this query -
SELECT * FROM table WHERE type = 'Mango' AND key = 'AP123'
but this is very complex to write the same code multiple times to get one result, here table key column value is the same, and on this basis I want to
Output will: 1 | Mango | 50 | AP123

but my requirement is like below -
SELECT * FROM table WHERE key = 'AP123'
let mango = 50
let banana = 20
let apple = 30

this is possible in any other way to achieve the goal, sorry for my bad English

SELECT * FROM table WHERE type IN (‘Mango’,‘Banana’,‘Apple’) AND key = ‘AP123’

yes, but How I store the value in a variable like this
let mango = 50
let banana = 20
let apple = 30

why do you want to store somethiing in a variable?

if you were able to do that, what are the results you expect from the query?

I think this is not a SQL problem but more a general kind of not understanding arrays.

Maybe the TO should lerne how to work with arrays in whatever language he is developing.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.