473,396 Members | 1,749 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,396 software developers and data experts.

Getting unique results

258 100+
Hi everyone
You see an example table below.. I'm trying to get one of each (day) using DISTINCT command...
Expand|Select|Wrap|Line Numbers
  1. +---------------------------+
  2. |    day       |  weather   |
  3. +---------------------------+
  4. |   Monday     |    Good    |
  5. |   Tuesday    |    Bad     |
  6. |   Wednsday   |    worst   |
  7. |   Tuesday    |    Good    |
  8. |   Wednsday   |    Bad     |
  9. +---------------------------+
  10.  
Here's the code :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT day FROM mytable 
  2.  
Actually it works but the problem is that this one only returns the day column.. but i need to get both columns and if i use this code :
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT day,weather FROM mytable 
  2.  
Then it doesn't return the same result becuase DISTINCT takes effect on both columns

Here's the result I'm expecting:

Expand|Select|Wrap|Line Numbers
  1. +---------------------------+
  2. |    day       |  weather   |
  3. +---------------------------+
  4. |   Monday     |    Good    |
  5. |   Tuesday    |    Bad     |
  6. |   Wednsday   |    worst   |
  7. +---------------------------+
  8.  
Thanks
Sep 27 '07 #1
3 1391
mwasif
802 Expert 512MB
Use GROUP BY instead of DISTINCT.
Expand|Select|Wrap|Line Numbers
  1. SELECT `day`, weather  FROM mytable GROUP BY `day`
The use of GROUP_CONCAT() may be of you interest.
Expand|Select|Wrap|Line Numbers
  1. SELECT `day`, GROUP_CONCAT(weather)  FROM mytable GROUP BY `day`
Sep 27 '07 #2
bnashenas1984
258 100+
It's working now

Thank you so much
Sep 27 '07 #3
mwasif
802 Expert 512MB
You are welcome, post back whenever you need help.
Sep 27 '07 #4

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

Similar topics

6
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
5
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
9
by: Rolf Kemper | last post by:
Dear Experts, I got stuck with the following problem and need your help. What I wnat to do is to get a set of distinct nodes. Before the distinct I have selected the multiple occourences...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
6
by: Uday | last post by:
Hi everyone, I have a ASP page that triggers a db-side stored procedure. At the end of the procedure, it spits out a log file, that this ASP page reads and displays for the users. But the...
2
by: Jimmy Stewart | last post by:
Ok, I'm trying to write a query that is starting to wear me down. What I'm trying to do is create a year end report that gets sent to all of my customers who meet two criteria. One they are...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
4
by: kdubble | last post by:
Hi I am trying to get the results of a query to show only unique student records (not duplicates). Is there a simple way to make the criteria field do this? I am not too familiar with SQL. ...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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
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,...

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.