Productive Edge | Microsoft at Productive Edge

Sep/10

6

Quick SQL snippit

I occasionally need to get some representative values from a table for testing and thought my solution might be something worth sharing.  I tend to think in nested selects and go back and clean up code into joins where appropriate.  Below you will see that I am using a group by and a min function to identify single instances of different types, and then pulling the required data in an outer select:

SELECT
	UserName
FROM
	Users
WHERE
	UserID in
	(
	SELECT
		MIN(UserID)
	FROM
		USERS
	WHERE
		Active = 1
	GROUP BY
		TypeCode
	)

· ·

No comments yet.

Leave a Reply

Security Code:

<<

>>

Theme Design by devolux.nh2.me