Reputation: 3
So here's the problem I can't work around today.
I want to grab some details from a database. I'm not sure how to explain this. But here goes.
Database Example:
1 | Description | abc
2 | Description | abc
3 | Description | def
I want to select the first row with the identifier "abc" and then I want to skip the next row which has the same field "abc".
I'm trying to use this in a SELECT mysql_query in PHP
Upvotes: 0
Views: 980
Reputation: 500
select id, description, identifier
from table group by identifier order by id asc;
Upvotes: 0
Reputation: 1962
This?
SELECT DISTINCT(identifier), title, description FROM tablename
It will also return the row with 'def' in this case.
Upvotes: 1
Reputation: 1035
select min(TITLE) as TITLE, DESCRIPTION , IDENTIFIER
From your_table
Group by DESCRIPTION , IDENTIFIER
Upvotes: 0
Reputation: 1277
It appears that the integer field is called 'title'. This should grab the lowest title # but remove the duplicates as you requested.
select min(title) as firstTitle, description, identifier
from table_name
where identifier in (select distinct identifier from table_name)
group by description, identifier.
Upvotes: 0
Reputation: 204766
To get the complete row you can do
select * from your_table
where title in
(
select min(title)
from your_table
group by identifier
)
Upvotes: 1