[英]how to get the values from table which contains key value pair structure in oracle
I have a table with the below structure i want to get the name and address values based on id value.我有一个具有以下结构的表,我想根据 id 值获取名称和地址值。
i tried with below query but it didn't work.我尝试使用以下查询,但没有用。
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
You could use subqueries to get result sets for names and addresses, and then join them:您可以使用子查询来获取名称和地址的结果集,然后加入它们:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.