Need SQL Query for this situation.

  • Thread starter Thread starter Karthik D V
  • Start date Start date
K

Karthik D V

Hello All,

I have a table like this

ID CHARACTER
----------- ---------
1 A
2 A
3 B
4 B
5 C
6 D
7 D


I need result like this.
I need SQL query which will fetch the following result.

ID CHARACTER
----------- ---------
1 A
3 B
5 C
6 D


Answer to my question ASAP. I need it very badly.
 
Karthik D V said:
Hello All,

I have a table like this

ID CHARACTER
----------- ---------
1 A
2 A
3 B
4 B
5 C
6 D
7 D


I need result like this.
I need SQL query which will fetch the following result.

ID CHARACTER
----------- ---------
1 A
3 B
5 C
6 D


Answer to my question ASAP. I need it very badly.

Select
Min(T.Id) As Id,
CHARACTER
From
YourTable As T
Group By
CHARACTER
 
Karthik said:
I need SQL query which will fetch the following result.
Answer to my question ASAP. I need it very badly.

Hello Karthik,
You will probably receive better responses in a SQL related group, such
as microsoft.public.sqlserver. Include as much information as
possible, and also try not to use demanding terms like 'ASAP'.
 
Without using Group by clause.

??

SELECT 1 AS ID, 'A' AS CHARACTER
UNION ALL SELECT 3, 'B'
UNION ALL SELECT 5, 'C'
UNION ALL SELECT 6, 'D'


Though if you submit this I'm not sure you'll get a good mark...

This is also OT for this newsgroup. Try one of the SQL ones.
 
Philip said:
??

SELECT 1 AS ID, 'A' AS CHARACTER
UNION ALL SELECT 3, 'B'
UNION ALL SELECT 5, 'C'
UNION ALL SELECT 6, 'D'


Though if you submit this I'm not sure you'll get a good mark...

This is also OT for this newsgroup. Try one of the SQL ones.


It was a Microft Question.... This is how I solved. I know it is not a
better way. I need Better way for this.

SELECT DISTINCT
T1.ID,
T1.CHARACTER
FROM
TEST T1
INNER JOIN
TEST T2
ON T1.CHARACTER = T2.CHARACTER
AND T1.ID = (
SELECT MIN(T3.ID)
FROM
TEST T3
WHERE T3.CHARACTER = T1.CHARACTER
)
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top