Selecting more than 1 column using Distinct?
Posted: Wed Nov 05, 2003 8:23 am
Hi,
I have the following table called actions with the following fields:
action_id tinyint unique auto_increment, (this is the primary key)
action_name varchar(20),
service_id tinyint
I am trying to use the following sql query to return all distinct action names and their corresponding action_id:
select distinct action_name,action_id from actions
However, this returns all of the records in the table. I assume because it is looking for distinct action_id as well? All of the action_id's will be distinct because action_id is the primary key.
I only want it to search for distinct action_name and not the distinct action_id like the query is doing at the moment, but I do want it return the action_id value along with the distinct action_names.
I hope this makes sense!
Thanks in advance,
Dan
I have the following table called actions with the following fields:
action_id tinyint unique auto_increment, (this is the primary key)
action_name varchar(20),
service_id tinyint
I am trying to use the following sql query to return all distinct action names and their corresponding action_id:
select distinct action_name,action_id from actions
However, this returns all of the records in the table. I assume because it is looking for distinct action_id as well? All of the action_id's will be distinct because action_id is the primary key.
I only want it to search for distinct action_name and not the distinct action_id like the query is doing at the moment, but I do want it return the action_id value along with the distinct action_names.
I hope this makes sense!
Thanks in advance,
Dan