473,411 Members | 2,210 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,411 software developers and data experts.

The DISTINCT command with multiple columns

Hi guys,

What i want to do is use a query that will return one of each type regardless of the other in there, for example.

i have a list of unit unit 3131,3132,3133 etc and they have a status attached to them of red, green or yellow.

when i run a select statment on them as below i get the results

unit 3131 - red
unit 3132 - green
unit 3132 - red

i knopw that this is becasue the DB is seeing the second two as distinct, what i want is just one of all the unit regardless of second or thrid entries.

so the statment i am using is
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT Unit, Status FROM tblAnalysis WHERE Unit LIKE '313%'
any help would be great

Thanks

Andrew
Nov 12 '08 #1
1 5449
mwasif
802 Expert 512MB
Use GROUP BY like
Expand|Select|Wrap|Line Numbers
  1. SELECT Unit, Status FROM tblAnalysis WHERE Unit LIKE '313%'
  2. GROUP BY Unit
Or you can use GROUP_CONCAT() to list all the status
Expand|Select|Wrap|Line Numbers
  1. SELECT Unit, GROUP_CONCAT(Status) FROM tblAnalysis 
  2. WHERE Unit LIKE '313%'
  3. GROUP BY Unit
Nov 12 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Florian | last post by:
Hi, I have a table that contains log data, usually around a million records. The table has about 10 columns with various attributes of the logged data, nothing special. We're using SQL Server...
8
by: Richard | last post by:
This is probably easy but I can't work it out. I have this statement SELECT DISTINCT TOP 100 PERCENT dbo.CIF_PlaceReference.Name FROM dbo.CIF_Departures INNER JOIN dbo.CIF_PlaceReference...
3
by: Dean | last post by:
I want to build query to return how many rows are in this query: select distinct c1, c2 from t1 But SQL won't accept this syntax: select count (distinct c1, c2) from t1 Does someone know how...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
6
by: zaphod | last post by:
I need to select unique combinations of 4 columns from one table and insert them into a new table but I can't think of any way of finding unique combinations of more than 1 column since SELECT...
2
by: vvyshak | last post by:
Hi all... I have a table in which some columns has distinct values and some has duplicates..i wan to select all the columns with distinct values....no problem if rows has null value in it....i...
4
by: Mina Patel | last post by:
Hi trying to find the number of duplicate tuples/records in table based on multiple columns ie. select count(distinct list multiple column key ) from x where date = y HAVING ( COUNT(multiple...
1
by: camurtha | last post by:
I have the following code: SELECT DISTINCT ON (REQUEST_ID) BATCH_ID, REQUEST_ID FROM VOLUNTEER_REQUEST I am recieving the error 'ORA-00936: missing expression' what am I doing wrong? ...
17
by: ukchat | last post by:
I.m creating a dynamic query to pull out workbooks from my database the table structure is below. Table: curricworkbooks Columns: ID, curric, assessment, topic, workbook, filename Example data...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.