DISTINCT in SQL - Again !! - Please help

Results 1 to 2 of 2

Thread: DISTINCT in SQL - Again !! - Please help

  1. #1
    Perini14 Guest

    Default DISTINCT in SQL - Again !! - Please help

    Ok, I&#039;m posting again the same problem, because the first time I did not get an answer! The problem is...<BR><BR>How to get recordset without duplicates in just 2 columns? Lets say that I have a table with addresses (firstname, lastname, address, city...). If I use this statement: <BR><BR>select distinct firstname, lastname from table1 <BR><BR>then in recordset I can&#039;t access the address or city field!! But, if I include address and city in sql statement, then the distinct command will affect the other fields, and I will have records with duplicate firstname and lastname. <BR>I&#039;ve tryed something like this: <BR><BR>select (distinct firstname, lastname), address, city from table1 <BR><BR>but that doesn&#039;t work! <BR><BR>Ok, lets make things clearer, what&#039;s the output I need: <BR>Let&#039;s say that my address table looks like this: <BR><BR>John Smith Address1 <BR>John Smith Address2 <BR>Ana Smith Address3 <BR>John Smith Address4 <BR><BR>The output I want is: <BR><BR>John Smith (any address is fine) <BR>Ana Smith (any address if fine) <BR><BR>Anybody know how to do it ??? <BR><BR><BR>Thanks! <BR>

  2. #2
    Join Date
    Dec 1969

    Default Group by

    select firstname,lastname,max(adress),max(city)<BR> from table1<BR> group by firstname,lastname<BR><BR><BR>Distinct is always applied to all columns. (Fundamental relational closure property.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts