Question

I have a query that as the following rows:

Id     |      key          | Value 
1         Type.name.1        Value1 
2         Type.name.2        Value2
3         Type.desc.1        Desc1
4         Type.desc.2        Desc2

And I need a query that returns this:

Type.NameId  | Type.DescId
1              3
2              4

How can I do this in Postgres?

Was it helpful?

Solution

SELECT *
FROM  (
   SELECT right(key, -10) AS name_id
   WHERE "value" ~~ 'Value%'
   ) n
FULL JOIN (
   SELECT right(key, -10) AS name_id, id AS desc_id
   WHERE "value" ~~ 'Desc%'
   ) d USING name_id;

Exact form depends on a lot of details missing in your question.

Your table design and naming convention give me the shivers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top