473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need SQL Query for this situation.


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.

Jan 18 '07 #1
5 1516
"Karthik D V" <Ka************@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
>
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

--
Regards
Grzegorz

Jan 18 '07 #2

Grzegorz Danowski wrote:
"Karthik D V" <Ka************@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...

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

--
Regards
Grzegorz

Without using Group by clause.

Jan 18 '07 #3

Karthik D V wrote:
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'.

Jan 18 '07 #4
On 18 Jan 2007 01:22:01 -0800, "Karthik D V"
<Ka************@gmail.comwrote:
>
Grzegorz Danowski wrote:
>"Karthik D V" <Ka************@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegr oups.com...
>
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

--
Regards
Grzegorz


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 Daniels
Jan 18 '07 #5

Philip Daniels wrote:
On 18 Jan 2007 01:22:01 -0800, "Karthik D V"
<Ka************@gmail.comwrote:

Grzegorz Danowski wrote:
"Karthik D V" <Ka************@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...

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

--
Regards
Grzegorz

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 Daniels

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

Jan 18 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Janssen | last post by:
Hello! Can anyone help me out with the following situation: (a) a single query with 550 id's in the IN-clause resulting into 800+ seconds; (b) 550 queries with a single id in the IN-clause...
1
by: Richard Hollenbeck | last post by:
Hello Newsgroup. You have all been very helpful in the past and I thank you. I try to ask relevant questions so that they don't just benefit me, but also benefit the group. I'm currently...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
3
by: ryanmhuc | last post by:
Is it possible to have a dynamic table name within a query or a table name that is a variable? This does not work but gives an example: SELECT * FROM concat('table', 'name') - OR - SET @table...
3
by: Martini | last post by:
Hello all. I have quite disturbing situation where I am not happy about the way how SQL handles the query. Situation is related to using user function in INNER JOIN select. Although the problem...
3
by: narpet | last post by:
Hello all... I'm having trouble with a query. Here's the situation: I have two tables, one that holds client info and another that holds invoicing info. The two tables have client number in...
1
by: shiniskumar | last post by:
i need a query to get a collection ... Following is the situation. ive got a collection in which item of each element is different. but each element has an item_id tat can be same.all these...
1
by: aknoch | last post by:
My basic situation is this - I ONLY want duplicates, so the opposite of DISTINCT: I have two tables. Ordinarily, Table1ColumnA corresponds in a one to one ratio with Table2ColumnB through a...
9
by: axlq | last post by:
I'm trying to figure out a MySQL query expression to match an email address. Here's the situation: User registers on my site with a "plus style" email address (username+key@example.com). This...
1
by: mbatestblrock | last post by:
I think I have a rather advanced question that I was hoping to find some good help with. I am still pretty new to VBA and I know that doesn't help my situation here. But here is what I am trying to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.