MS SQL Queries to retrieve data from tables

MS SQL Queries to retrieve data from tables


In this article, you will find basic to most puzzled Microsoft SQL Server queries to retrieve data from tables with an example.

techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

So, before starting let's create and populate tblstudent table using following script.


1
2
3
4
5
6
7
8
9
Create table tblStudent
(
	StudentId int,
	FirstName varchar(50),
	LastName varchar(50),
	Admission_fee int,
	Admission_date datetime,
	Branch varchar(50),
)

- tblstudent

StudentId FirstName LastName Admission_fee Admission_date Branch
1 John Smith 1000 2018-06-10 Computer Engineering
2 David Jones 1200 2018-06-20 Civil Engineering
3 Michael Johnson 900 2018-08-15 Chemical Engineering
4 Chris Lee 1500 2018-07-10 Electrical Engineering
5 Mike Brown 1600 2018-09-10 Mechanical Engineering
6 Lisa Smith 1800 2018-07-10 Computer Engineering
7 Mary Smith 1600 2018-06-11 Computer Engineering

  1. Write a SQL statement to display all students information
  2. Write a query to display a string "Hello World!"
  3. Write a query to display sum of two numbers 10 and 15
  4. Write a query to display only firstname and branch from table student
  5. Write a SQL query to display firstname and branch of student, who belongs to the branch 'Computer Engineering'
  6. Write a SQL query to get details whose firstname starts with name "David"
  7. Write a SQL query to get first name from tblstudent in upper case
  8. Write a SQL query to get first name from tblstudent in lower case
  9. Write a SQL query to get unique branch from tblstudent table
  10. Write a SQL query to combine FirstName and LastName and display it as "Full Name"
  11. Write a SQL query to get all student details from tblstudent whose "FirstName" contains 'a'
  12. Write a SQL query to get all student details from tblstudent whose "FirstName" start with 'd'
  13. Write a SQL query to get all student details from tblstudent whose "FirstName" ends with 'a'
  14. Write a SQL query to get list of all students whose first name start with 'Ma' or 'Da'
  15. Write a SQL query to get all students details from the tblStudent table order by FirstName Ascending
  16. Write a SQL query to get all students details from the tblStudent table order by FirstName Descending
  17. Write a SQL query to get all students details from the tblStudent table order by LastName Ascending and Admission fees descending
  18. Write a SQL query to get position of 'v' in name 'David' from tblstudent
  19. Write a SQL query to get firstname from tblstudent with Hello prefix
  20. Write a SQL query to get FirstName from tblstudent after removing white spaces from right side
  21. Write a SQL query to get FirstName from tblstudent after removing white spaces from left side
  22. Write a SQL query to get length of FirstName from tblstudent
  23. Write a SQL query to get FristName from tblStudent table after replacing 'a' with '$'
  24. Write a SQL query to get all students details from tblStudent whose first name starts with 'm' and name contains 4 letter
  25. Write a SQL query get all students details from tblStudent whose first name ends with 'a' and name contains 4 letters
  26. Write a SQL query get fristname from tblstudent not start with any single character between a-l
     




Related Topics



Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.