| SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it. |
|
|||
Select Query with different fieldsHello All...
I'm sure this is very simple to those who know... but I'm trying to do what I think should be a simple query, but I'm struggling to get exactly what I want... Suppose I have a table similar to the below: Table: email - firstname - lastname mrx@mycompany.com - Fred - Bloggs mrx@mycompany.com - F - Bloggs mrx@mycompany.com - Fred - Blogs me@here.com - Pam - Smith me@here.com - Pamela - Smith you@there.com - Tom - Thumb All I want to do is return / query that returns one value for each entry as follows: mrx@mycompany.com - Fred - Bloggs me@here.com - Pam - Smith you@there.com - Tom - Thumb I've used the DISTINCT keywork, but because the other fields are unique, all rows are returned still.... Similarly, If I wanted to query all records in the table that have multiple records for an email address in the table above, how would I do that? Many thanks in advance.... |
|
|||
|
Hi,
Does this solve the issue: Code:
SELECT email, max(firstname),max(lastname) FROM t GROUP BY email; Hope this helps, Dimitar |