zinka
zinka

Reputation: 239

distinct in mysql

i want to select from a mysql table

title , url from the table

title can be duplicate so i need distinct title from them'

if i use sachin's code then i find duplicate rows so how i can get the information where title not show again as the result. means no duplicate title get from table in mysql

Upvotes: 2

Views: 173

Answers (3)

Sachin Shanbhag
Sachin Shanbhag

Reputation: 55489

SELECT distinct a.title, a_url FROM blah WHERE a.cID = 1856 

Upvotes: 0

zinka
zinka

Reputation: 239

here is the sollution

SELECT * FROM blah WHERE info.cID = 1856 GROUP BY title

Upvotes: 0

Quassnoi
Quassnoi

Reputation: 425261

SELECT  DISTINCT *
FROM    mytable

Update:

SELECT  b.title, b.url
FROM    (
        SELECT  DISTINCT title
        FROM    blah
        WHERE   cID = 1856
        ) bd
JOIN    blah b
ON      b.id = 
        (
        SELECT  bi.id
        FROM    blah bi
        WHERE   bi.cID = 1856
                AND bi.title = bd.title
        ORDER BY
                cid, title, url, id
        LIMIT 1
        )

Create an index on (cid, title, url, id) for this to work fast.

Upvotes: 5

Related Questions