0

Looking for a way to only select rows with unique email addresses but also I need the other field data.

Currently have this:

$mainQuery = $mysqli->query("SELECT DISTINCT(`email`) FROM valuations");

Which brings my results down from 9208 to 7848 so that works fine.

I have 3 or 4 tables with 10000 or so rows each and we are now looking to create one single 'customers' table. I am making a script to 'import' all of these rows into the customers table.

The rows I need extra are e.g. 'username' 'number' 'title' etc.

These do not need to be unique, just the email.

I tried:

$mainQuery = $mysqli->query("SELECT DISTINCT(`email`),username FROM valuations");

But that returned more rows that before, how should I go about this?

Thanks.

Lovelock
  • 7,689
  • 19
  • 86
  • 186

1 Answers1

0

Use group by:

SELECT email, MIN(username)
FROM valuations
GROUP BY email;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786