croshim
croshim

Reputation: 33

MySQL query Select data

Trying to make query for 4 hours. For example i have such data:

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  

How to chose distinct title and distinct number_link ? I have marked with "<-" what i want to get from query. Thanks in advance.

Upvotes: 0

Views: 87

Answers (4)

John Woo
John Woo

Reputation: 263693

This query will allows you to get all the column with in the row not just title and number_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

Upvotes: 1

Hind Walieddine
Hind Walieddine

Reputation: 1

SELECT *
FROM table_name
GROUP BY title, number_link

Upvotes: 0

Somnath Paul
Somnath Paul

Reputation: 190

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

Upvotes: 0

davey
davey

Reputation: 1791

SELECT title FROM table GROUP BY title, number_link

Upvotes: 0

Related Questions