Hi
As the selected list by
GROUP BY command does not carry coulmns which are not in the GROUP BY clause, probably more useful if you use the following get-around where condition. It works exactly like
group by but it still carries other columns in a single query.
if object_id('tempdb..#customer_tbl') is not null
drop table #customer_tbl
CREATE TABLE #customer_tbl(Col1 INT identity(1,1), Col2 int, Col3 varchar(40), Col4 DateTime)
INSERT INTO #customer_tbl Values(200131, 'John Doe', '2010/01/01')
INSERT INTO #customer_tbl Values(200145, 'Minnie Young', '2009/01/11')
INSERT INTO #customer_tbl Values(300157, 'Dopie Jackson', '2008/01/01')
INSERT INTO #customer_tbl Values(300157, 'Dopie Boowinkle', '2009/11/01')
INSERT INTO #customer_tbl Values(300328, 'Mary Lou Redding1', '2007/01/06')
INSERT INTO #customer_tbl Values(300328, 'Mary Lou Redding2', '2009/02/19')
INSERT INTO #customer_tbl Values(300328, 'Mary Lou Redding3', '2010/04/01')
INSERT INTO #customer_tbl Values(200146, 'Sophie Den', '2006/01/11')
INSERT INTO #customer_tbl Values(200147, 'Simon Seng', '2006/01/11')
INSERT INTO #customer_tbl Values(200148, 'Jim Nakamura', '2006/01/11')
INSERT INTO #customer_tbl Values(200148, 'David Nakamura', '2006/01/11')
INSERT INTO #customer_tbl Values(200149, 'William Park', '2006/01/11')
SELECT * FROM #customer_tbl t
WHERE
(
Select Count(*)
FROM #customer_tbl
WHERE t.Col2=Col2
)>=2
Order By Col2,Col3