HI, i have two tables 1- name, id, code 2- id, value, concept
One name can have two concepts and two values. i want to retreive this: Id, name, value1, value2.
How can i do that?
Tanks
HI, i have two tables 1- name, id, code 2- id, value, concept
One name can have two concepts and two values. i want to retreive this: Id, name, value1, value2.
How can i do that?
Tanks
You could do for example
SELECT t.id, t.name, t.value as value1, t2.value as value2
FROM table2 as t
INNER JOIN table2 as t2 ON t.id = t2.id AND t.value <> t2.value
but there are many other ways available.
EDIT
SELECT t1.id, t1.name, t2a.value as value1, t2b.value as value2
FROM table1 as t
INNER JOIN table2 as t2a ON t.id = t2a.id
INNER JOIN table2 as t2b ON t.id = tba.id AND t2b.value <> t2a.value
Note: solution assumes that there are 2 rows per id (in case of 3 rows you will get multiple rows per id in the results)
This will be a start:
SELECT
T.id,
T.name,
V1.value AS value1,
V2.value AS value2
FROM
My_Table T
LEFT OUTER JOIN My_Values V1 ON V1.id = T.id
LEFT OUTER JOIN My_Values V2 ON V1.id = T.id
But the question here is, what differentiates value 1 from value 2? Is it a value in "concept", is it a matter of which was added to the DB first? Which has a higher id column for some other column? Your requirements are not fully spelled out.