Microsoft Interview Question
Software Engineer / DevelopersI think one could use Distinct here:
Select Distinct col
from A;
This would give you only unique values in the table...as mentioned above you would get { a,b } if the values in the col is { a,b,a }
I think both a and b wi;; be returned becoz b is different from a in { a,b } and a is different from b in {b,a}
so i think effectively its asking to find all rows where a change occurs in the column...
i dont know how to construct an SQL statement for this tho
Using cursors! -- you just funked. The person who asked the question is an idiot (or likely a C# developer pretending to be a SQL developer -- it's a bad translation of a standard C# or Java question).
Declare @workingspace table(id int Identity(1,1), data varchar(max))
INSERT INTO @workingspace (data)
SELECT LastName from SalesLt.Customer
Select top 1 data from @Workingspace
UNION
Select A.data from @workingspace A
JOIN @workingspace B ON A.ID=B.Id-1
The above query may not return repeatable results. AbhiM is correct
table{col}
- Anonymous November 28, 2009Do a cross product on the values. Values that are *NOT* repeated will have just one row where both the values are same in the cross product. We, do a group by on the cross product and select only those rows where count(*) = 1. Comments?
select A.col from
table as A, table as B where
A.col = B.col group by
A.col having count(*) = 1