Shamrox wrote:I am attempting to output a mailing list with the standard name, company, address, etc info, but a persons name should only show once.
The query below is taking a list of pubids, of which a persons names could appear on multiple pupid lists. The final output should only show their name once. I run the query against a few lists that i know the name shows on each to see if it returns their name only once, and it returns nothing. Could you please tell me if I have this written wrong and suggest a fix?
SELECT DISTINCT firstname, lastname, companyname, street1, street2, city, state, zipcode, zip4, country, countrycode, MAX(quantity) FROM moms_customer, moms_lists WHERE moms_customer.custnumber = moms_lists.custnumber AND pubid IN ('".$_POST['display']."') GROUP BY lastname
DISTINCT only returns 100% unique records. So you could have two records that have all the columns the exact same except one, and it is considered distinct.
From looking at your query, you have a lot of amibguity in your statement, meaning that you don't define which table some of your fields are from.
Take a look at this:
<?php
$sql = "SELECT DISTINCT c.firstname, c.lastname, c.companyname, c.street1, c.street2, c.city, c.state, c.zipcode, c.zip4, c.country, c.countrycode, MAX(l.quantity)
FROM `moms_customer` c, `moms_lists` l
WHERE c.custnumber = l.custnumber
AND l.pubid IN ('".$_POST['display']."')
GROUP BY c.lastname";
?>
I'm not sure if I matched up the tables and fields correctly, but you get the idea. Make sure that you specify which table (c or l) each field is from.
Not sure if that will fix your problem, but take a look at it and let me know.