F M's Library tagged → 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
Nonoh | Free call stuff... *Turkiye is free
easy solution totally free upto 3 minutes.
SQL UNION and UNION ALL
\n <clipping>The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.</clipping>\n
Time-Based Blind SQL Injection with Heavy Queries: MVP Article of the Month - September 2007
Clever Blind SQL Injection trick when you can't use BENCHMARK, WAITFOR DELAY, sleep etc.
Should be used as a last resort.
SQL Function Reference: SQL Server vs. Oracle
Great and simple reference for ORACLE and MSSQL functions
1 - 13 of 13
Showing 20▼ items per page
Selected Tags
Related Tags
Sponsored Links
Ads by Google
Top Contributors
Groups interested in SQL
Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »
Join Diigo
