开发者

distinct in mysql

开发者 https://www.devze.com 2023-01-14 00:51 出处:网络
i want to select from a mysql table title , url from the table title can be duplicate soi need distinct title from them\'

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消