MySQL查询选择数据

时间:2013-09-26 11:34:11

标签: php mysql sql select

尝试查询4小时。例如,我有这样的数据:

did   title      number_link    ltitle
35  about.html        1          NULL    <- this
35  about.html        2          NULL    <- this
36  about.html        1          NULL
35  contact.php       1          NULL    <- this  
35  contact.php       3          NULL    <- this  
36  contact.php       1          NULL  

如何选择不同的标题和不同的number_link? 我用“&lt; - ”标记了我想要查询的内容。 提前谢谢。

4 个答案:

答案 0 :(得分:1)

此查询将允许您获取行中的所有列,而不仅仅是titlenumber_link

SELECT  a.*
FROM    tableName a
        INNER JOIN
        (
            SELECT  title, number_link, MIN(did) did
            FROM    tableName
            GROUP   BY title, number_link
        ) b ON a.title = b.title AND
                a.number_link = b.number_link AND
                a.did = b.did

答案 1 :(得分:0)

SELECT title FROM table GROUP BY title, number_link

答案 2 :(得分:0)

SELECT *
FROM table_name
GROUP BY title, number_link

答案 3 :(得分:0)

SELECT title,number_link FROM table GROUP BY title,number_link;