select table query.

indradaman sharma
indrada...
116 Points
14 Posts
1 A
1 B
1 C
2 A
1 D
2 B
2 c

Select this table so we get below result 

1 A  1
1 B 2
1 C  3
2 A 1
1 D 4
2 B 2
2 C 3

 

Please give me result query

Views: 9844
Total Answered: 3
Total Marked As Answer: 0
Posted On: 07-Mar-2017 05:53

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
4916 Points
27 Posts
         

Hi Indradaman,

Please give more detail, what you want?

Posted On: 08-Mar-2017 04:36
indradaman sharma
indrada...
116 Points
14 Posts
         

i have first table and by running select query want answer like second table.

Posted On: 08-Mar-2017 09:40
Rahul Maurya
Rahul M...
4916 Points
27 Posts
         

Let's do some crazy query:

I created 'TestTable' with two field as bellow:

id name
1 A
1 B
1 C
2 A
1 D
2 B
2 C

And I want result as:

id name value
1 A 1
1 B 2
1 C 3
2 A 1
1 D 4
2 B 2
2 C 3

The query will be like following:

SELECT TestTable.id, TestTable.Name, temp.Value
FROM TestTable INNER JOIN (SELECT 'A' AS Name, 1 AS Value
UNION
SELECT 'B' AS Name, 2 AS Value
UNION
SELECT 'C' AS Name, 3 AS Value
UNION
SELECT 'D' AS Name, 4 AS Value
) temp on temp.Name=TestTable.Name
Posted On: 09-Mar-2017 00:54
 Log In to Chat