0

I have a simple query and I'd like to only reveal the unique rows

SELECT
name, email, phone
FROM
contacts

in other words, if the email appears multiple times and its the same email, we only show 1 name and 1 email once.

How is this question different from the suggested answer?

If the name is missing and another record has the name, the query would return the query that contains the most complete data.

The GOAL: is to merge the data fields, so that if one record has a name+email and another record has email+phone and the phone# or the email is a match - it will COMBINE it into 1 nice record

with name+phone+email.

That's how this question is different from similar questions.... as our log files when people submit optin forms are sometimes email only, other times, name and email, other times, phone and email - we want to combine all these into a single contact record.

Thanks!

Thanks!

Viktor
  • 517
  • 5
  • 23
  • 1
    Does this answer your question? [Remove duplicate rows in MySQL](https://stackoverflow.com/questions/3311903/remove-duplicate-rows-in-mysql) There are example answers there without using ALTER. – Paul T. Nov 12 '22 at 22:55
  • I read that article and it does not really answer my question. Read the question. I posted an answer which works kind of, but it does not take into consideration that a database with multiple records, some with email and some with name will prioritize the record WITH the name vs. the one that shows up sequentially or by timestamp. – Viktor Nov 12 '22 at 23:13

1 Answers1

0
SELECT
name, email, phone
FROM
contacts
group by email

But this will only return records where the email matches the record that is either the most recent or the default sort order.

Viktor
  • 517
  • 5
  • 23