Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select distinct teacher from class etc.
- select distinct teacher, student etc.
- SELECT teacher, COUNT(student) AS amountStudents
- FROM ...
- GROUP BY teacher;
- SELECT * FROM class WHERE teacher IN (SELECT DISTINCT teacher FROM class)
- DECLARE @table TABLE (
- [Teacher] [NVarchar](256) NOT NULL ,
- [Student] [NVarchar](256) NOT NULL
- )
- INSERT INTO @table VALUES ('Teacher 1', 'Student 1')
- INSERT INTO @table VALUES ('Teacher 1', 'Student 2')
- INSERT INTO @table VALUES ('Teacher 2', 'Student 3')
- INSERT INTO @table VALUES ('Teacher 2', 'Student 4')
- SELECT
- T.[Teacher],
- (
- SELECT TOP 1 T2.[Student]
- FROM @table AS T2
- WHERE T2.[Teacher] = T.[Teacher]
- ) AS [Student]
- FROM @table AS T
- GROUP BY T.[Teacher]
- Teacher 1, Student 1
- Teacher 2, Student 3
- SELECT t1.a
- , (SELECT TOP 1 b FROM Table1 t2 WHERE t1.a = t2.a) AS b
- , (SELECT TOP 1 c FROM Table1 t2 WHERE t1.a = t2.a) AS c
- , (SELECT TOP 1 d FROM Table1 t2 WHERE t1.a = t2.a) AS d
- FROM dbo.Table1 t1
- WHERE (your criteria here)
- GROUP BY t1.a
- select class_name, count(teacher)
- from class group by class_name having count(teacher)=1
- select teacher, count(student)
- from class group by teacher having count(student)=1
- select distinct teacher from class
- SELECT DISTINCT ColA FROM Table WHERE ...
- Select Distinct column1 -- where your criteria...
- Select teacher_id, count(*)
- from teacher_table inner join classes_table
- on teacher_table.teacher_id = classes_table.teacher_id
- group by teacher_id
- Select * from tbl
- Where ColA in (Select ColA from tbl Group by ColA Having Count(ColA) = 1)
- select cola,colb,colc
- from yourtable
- where cola in
- (
- select cola from yourtable where your criteria group by cola having count(*) = 1
- )
- declare @temp as table (colA nchar, colB nchar, colC nchar, colD nchar, rownum int)
- insert @temp (colA, colB, colC, colD, rownum)
- select Test.ColA, Test.ColB, Test.ColC, Test.ColD, ROW_NUMBER() over (order by ColA) as rownum
- from Test
- select t1.ColA, ColB, ColC, ColD
- from @temp as t1
- join (
- select ColA, MIN(rownum) [min]
- from @temp
- group by Cola)
- as t2 on t1.Cola = t2.Cola and t1.rownum = t2.[min]
Add Comment
Please, Sign In to add comment