473,836 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting unique results

258 Contributor
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 1414
mwasif
802 Recognized Expert Contributor
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 Contributor
It's working now

Thank you so much
Sep 27 '07 #3
mwasif
802 Recognized Expert Contributor
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
2502
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?? Thanx! Wm <?PHP include('dbconn.php');
303
17861
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
5
10880
by: Kamil | last post by:
Hello What should I use for better perfomance since unique constraint always use index ? Thanks Kamil
9
2437
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 already sucsessfully. However , the rest does not work as expected. Hope someone can help on that. Rolf
13
10155
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 parent table. ----------------------------
6
1959
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 problem is that the database-stored Proc could take anything between 10 secs - to - 10 mins. I dont want the page to time out . Is there a way, like the airlines websites do, where I can just show an animated gif while the procedure runs and redirect...
2
2237
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 'Residential' customer AND they have had business with us during this past year. My report is based on a query. The query has two tables associated with it. One is tblClients which provides client name, account type and the other relevant mailing...
6
2729
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 action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type=\"submit\"...
4
31260
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. I have a student_info table, a session_info table, and a services_to_students table. What I'd like to do is query the tables to get a list of all students served between certain dates. Now, of course, between those dates,
2
4455
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 statistical purposes. I've been using Here's the situation: I have two main tables:
0
10859
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10601
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10260
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6982
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.