0

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:

TITLE | DESCRIPTION | IDENTIFIER

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

1
  • 1
    group by identifier? Commented Aug 22, 2013 at 16:18

5 Answers 5

1

To get the complete row you can do

select * from your_table
where title in 
(
  select min(title)
  from your_table
  group by identifier
)
Sign up to request clarification or add additional context in comments.

1 Comment

Will this not always return true as you're not stopping it from matching itself in that subselect?
1

This?

SELECT DISTINCT(identifier), title, description FROM tablename

It will also return the row with 'def' in this case.

Comments

0

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.

Comments

0
select min(TITLE) as TITLE, DESCRIPTION , IDENTIFIER 
From your_table
Group by DESCRIPTION , IDENTIFIER 

1 Comment

I used the title numbers an example. Sorry for the confusion !
0
select id, description, identifier 
from table group by identifier order by id asc;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.