I'm using DISTINCT to get one of each title out of my table.
Here is my table: -
+---------------------------+
-
| title | weather |
-
+---------------------------+
-
| Monday | Good |
-
| Tuesday | Bad |
-
| Wednsday | worst |
-
| Tuesday | Good |
-
+---------------------------+
-
Query = - SELECT DISTINCT title , weather FROM mytable
And my question is:
in this case there is 2 rows with same title (Tuesday). so just one of them will be showed but we also have 2 rows with same weather ( Good ) which dont have same title... I need to know if only one of these three rows will be showed or 2?
What I mean is that I need only unique titles not unique weather...
8 11973 pbmods 5,821
Recognized Expert Expert
Heya, bnashenas.
Please use CODE tags when posting source code:
[CODE=MySQL]
MySQL code goes here.
[/CODE]
Use a GROUP BY clause: -
SELECT
-
DISTINCT
-
`title`,
-
`weather`
-
FROM
-
`mytable`
-
GROUP BY
-
`title`,
-
`weather`
-
What exactly does it do? I mean GROUP BY
What exactly does it do? I mean GROUP BY
Read all about it here. pbmods 5,821
Recognized Expert Expert
Heya, Bnashenas.
Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Sorry guys
I did all you said but I think I'm still having problem..
What i need is that I want DISTINCT to take effect only on 1 Column ( title ) and I also need to get all rows...
Check this: -
SELECT DISTINCT title FROM mytable
-
But the problem is that this command only returns title column... I mean if i use -
$result=mysql_fetch_array();
-
in php i only get result[title] but i need result[weather] too
As you said I also used GROUP BY and i thought it was working but it wasn't
Thanks agin for your replies
pbmods 5,821
Recognized Expert Expert
Heya, Bnashenas.
What's your query look like?
Hello pbmods...
Thanks for your replies.. Actually i solved the problem by using this command : -
SELECT * FROM mytable GROUP BY title,weather
-
Thanks again
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alex Satrapa |
last post by:
I have a table from which I'm trying to extract certain information. For
historical reasons, we archive every action on a particular thing
('thing' is identified, funnily enough, by 'id'). So the only way to
find out the current state of a particular combination of attributes is
to "select distinct on (id, ...) ... order by date desc".
In...
|
by: LarryR |
last post by:
The following XSLT works fine using MSXML 4.0 (e.g I receive a result in
about 20 seconds), but effectively hangs in both .NET 1.0 sp2 with the XML
hot fix and NET 1.1. My source XML file is large at over 46,000
<atl_client> nodes
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"...
|
by: Fred Zuckerman |
last post by:
Can someone explain the difference between these 2 queries?
"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"
Thanks,
Fred Zuckerman
|
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 DISTINCT only works on
single columns. Any ideas?
zaphod
|
by: @sh |
last post by:
This may be a really simple question, but I always have problems with
Distinct queries.
In this instance, I have a table of Delivery addresses, some will be exactly
the same EXCEPT for the DeliveryID field, but eitherway I need the
DeliveryID so that I can pass it onto the next form.
So, I need to run a query that will find only addresses...
| |
by: NeoGeo |
last post by:
I have a problem with a SQL SELECT query. As far as my research goes i figured out that UNIQUE is used when you have one column that you whant unique and DISTINCT is used when you have more than one column that you want to all be unique. But i have a query where i want just some of the columns to be unique and some not. Here is the full query...
|
by: newnewbie |
last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our system and thinks I am omnipotent now and can extract any data out of it in the form he wants….The truth is, though I know SOME Access, I am not a...
|
by: shira |
last post by:
Hi,
Looking to see if someone might have an explanation for this behavior.
Is it a bug? Corruption?
I have been able to reproduce the problem with only 2 rows and 1
field. Here is the table:
Field1
231.2
|
by: omnittha |
last post by:
I would like to pull unique records of a SINGLE column but not the other related columns. When I use DISTINCT, it pulls up all the records which are unique across the columns. Here is the code....
SELECT distinct columnA,columnB,columnC
FROM Table
ORDER by columnA,columnB,columnC;
What I would like to see, is Distinct records from column...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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...
|
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |