Table Design:
CREATE TABLE
[dbo].[student](
[FirstName]
[nvarchar](50) NULL
[ID] [int] NULL,
[Technology]
[nvarchar](50) NULL
) ON [PRIMARY]
GO
select * from
student
FirstName
|
ID
|
Technology
|
Ravi Sharma
|
1
|
DotNet
|
Ravi
|
3
|
DotNet
|
Avdesh
|
4
|
DotNet
|
CP
|
5
|
JAVA
|
ROHIT
|
6
|
ASP
|
AMIT
|
7
|
JS
|
RITU
|
8
|
VB
|
ATUL
|
9
|
C
|
GINI
|
10
|
SQL
|
1st Query:
SELECT A.*
FROM (SELECT TOP 1 * FROM student ORDER BY ID) A
UNION ALL
SELECT B.* FROM (SELECT TOP 1 * FROM student ORDER BY ID DESC) B
Query Output:
FirstName
|
ID
|
Technology
|
Ravi Sharma
|
1
|
DotNet
|
GINI
|
10
|
SQL
|
2nd Query:
SELECT * FROM student WHERE ID IN (SELECT TOP 1 MIN(ID) ID FROM student
UNION ALL
SELECT TOP 1 MAX(ID) ID FROM student)
Query Output:
FirstName
|
ID
|
Technology
|
Ravi Sharma
|
1
|
DotNet
|
GINI
|
10
|
SQL
|
No comments :
Post a Comment