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
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.
here is the sollution
SELECT * FROM blah WHERE info.cID = 1856 GROUP BY title
SELECT distinct a.title, a_url FROM blah WHERE a.cID = 1856
精彩评论