Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Selecting On Row NEWBIE ??

Author  Topic 

webstep
Starting Member

3 Posts

Posted - 2003-07-09 : 20:30:09
Selecting one row from a table

Hi all I have a table that has some rows like the example 1
The: represent the filed in the table

I wish to write a sql query that it produces one row for the result when querying colum G so output looks like example 2

Example 1

A : B : C : D : E :F : G
The : cat : jumped : over :the : mat : 1
The : cat : jumped : over :the : mat : 1
The : cat : jumped : over :the : mat : 1
The : cat : jumped : over :the : mat : 1
The : cat : jumped : over :the : mat : 2
The : cat : jumped : over :the : mat : 2
The : cat : jumped : over :the : mat : 2

Example 2

The cat jumped over the mat 1
The cat jumped over the mat 2

O/S windows 2000 / SQL M/S SQL2000

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-07-09 : 20:34:05
For one thing, why do you have duplicate rows? You can certainly remove them in a query:

SELECT DISTINCT A, B, C, D, E, F, G FROM myTable

...but if your table was designed properly it would have constraints on it to prevent such duplicates from being inserted into the table in the first place.

Go to Top of Page

webstep
Starting Member

3 Posts

Posted - 2003-07-10 : 00:26:53
Actuality the fields are a bit different and I am creating a database for some music records
If you could shed some light on what I should be doing to make things a bit easier that would be appreciated

I have a data base structure like this

-----------------
Tracks
-----------------
Artist Text
Title Text
Track_No Numeric
Vol_Name Text
Vol_Ref_No Text
Price Money






Edited by - webstep on 07/10/2003 00:27:48
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2003-07-10 : 03:31:06
You need some criteria that determins which of the fields ABCDEF get shown for each different G.

Either of SELECT DISTINCT or a group by should help you in what you want to do.

-------
Moo. :)
Go to Top of Page
   

- Advertisement -