我有一个具有以下结构的表我想根据id值获取名称和地址值。
我试过以下查询,但它没有用。
select name,address from details where c_id=111
table name=**details**
c_id key value
111 name abc
111 email add@gmail.com
111 address h.no 22,hyderabad
222 name raj
222 email xyz@yahoo.com
222 address h.no 24,india
答案 0 :(得分:0)
您可以使用子查询来获取名称和地址的结果集,然后加入它们:
SELECT name, address
FROM (SELECT c_id, value AS name
FROM details
WHERE key = 'name') n
JOIN (SELECT c_id, value AS address
FROM details
WHERE key = 'address') a ON n.c_id = a.c_id