Skip to main content

F M's Library tagged TSQL   View Popular

04 May 08

SQL Server programming Select DISTINCT columns along with a NON-DISTINCT column

  • I tried to do the same thing myself and finally this is how I worked it out :



    SELECT

    rowCode <---- (Some unique numeral key)

    firstname,lastname,address1 <---- distinct columns

    plandate,plandate2 <---- non distinct columns



    FROM table



    WHERE rowCode IN (SELECT Min(rowCode) FROM table GROUP BY firstname,lastname,address1)



    ORDER by firstname



    This will return unique values for your distinct columns and will the first (min) value of your non distinct columns .

    ---------------------------------------------------



    Actually in your case, because your 'non distinct' column has a 'date' type, you can solve it more easily by using the following code :



    SELECT Bank, Account, Note, MAX(PlanDate)

    FROM table

    GROUP BY Bank, Account, Note

Record Locater for SQL Injection

Great script to found password/user etc. column and tables in SQL Injections (for MS SQL)

ferruh.mavituna.com/-locater-for-sql-injection-oku - Preview

SQL Injection TSQL

1 - 4 of 4
Showing 20 items per page

Diigo is about better ways to research, share and collaborate on information. Learn more »

Join Diigo