Join Distinct Id on non-distinct id (MySql)

SELECT t.ID, t.val_string, t.val_int,
FROM table1 AS t
    LEFT JOIN (subquery) AS v_table
        ON t.ID = v_table.ID

Sample fiddle

Related to : Join Distinct Id on non-distinct id (MySql)
MySQL - Select DISTINCT with Count Of That Distinct , Same Table
You need to use grouping if you want to achieve the result with aggregating the data. You can use COUNT function in this case: SELECT `language`, COUNT(`id`) FROM `words` GROUP BY `language`
Need sum of distinct values in one MySQL column grouped by the distinct value
This will return the name of the Country and the number of times that Country appeared in the column: SELECT country, COUNT(*) as count FROM Contact GROUP BY country ORDER BY count DESC it also returns the countries in order of most to least frequent.
"distinct count" and "distinct count if exists" in single MySQL select statement
without a subquery, improving speed select count(if(date_sent='2013-01-10',email, null)) as emails, count(distinct if(date_sent='2013-01-10',email, null)) as uniques, count(distinct email) as total_unique_email from sent_emails
Does 'select distinct' returns the first distinct value or last distinct?
I think there's a misunderstanding here: Your query does not return the records, only the distinct column values. Which, in your example, are 'Sam' and 'Tom'. They have no particular order which can safely be expected. It may be the natural order, or the order in which they are processed on the database (completely depending on the database implementation), or semi-random (such as iterating over
No SELECT DISTINCT exists but I get: The text data type cannot be selected as DISTINCT because it is not comparable
The UNION clause causes a DISTINCT. Blog post describing your exact problem: SQL unions and the text data type

Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © All Rights Reserved .