pTutorial

New way to learn Programming

SQL Queries Interview Questions

SQL Queries

This section covers all the basic SQL queries interview question which are frequently asked in the programming interview question with examples for java programming interview, PHP programming interview, DBA fresher, MySQL, Oracle interview and many more.

These SQL queries interview questions are important for fresher and experienced programmer also.

I. SQL Create Database and Create Table interview Questions

1. Create a SQL database named school.

CREATE DATABASE school;

2. Create a table with four field rollNo, name, city, marks in appropriate datatype.

CREATE TABLE student
(
rollNo INT,
name VARCHAR (20),
city VARCHAR (20),
marks INT,
);

3. Create table with primary key in school database.

CREATE TABLE student
(
rollNo INT NOT NULL,
name VARCHAR (20),
city VARCHAR (20),
marks INT,
PRIMARY KEY (rollNo)
);

II. SQL Queries on SQL Select.

4. Fetch all the Student details from the student table.

Select * from student;

5. Fetch rollNo, name from student table.

select rollNo, name from student;

6. Fetch all the unique city detail from student table.

SELECT rollNo, NAME FROM student GROUP BY city;

7. Fetch the rollNo using alias name "ID" from the student table.

SELECT rollNo ID FROM student;
SELECT rollNo AS StudentID FROM student;

8. Fetch unique student city from student table

 	 SELECT DISTINCT city FROM student;

9. Fetch first maximum marks student details.

 SELECT rollNo, NAME, city, MAX(marks) FROM student;

10. Fetch first minimum marks student details (Complete details).

SELECT rollNo, NAME, city, MIN(marks) FROM student;

11. Count the total number of entries or total number of student in student table using alias name “TotalStudent”.

SELECT COUNT(*) AS TotalStudent FROM student;

12. Count the total number of unique city from student table using alias name "UniqueCity".

SELECT COUNT(DISTINCT city) AS UniqueCity FROM student;

13. Fetch name of student from student table after removing white spaces (left and right) .

SELECT TRIM(NAME) FROM student;

14. Fetch the name of student and the length of name as length from student table

SELECT NAME,LENGTH(NAME) FROM student;

See Also


QUOTES OF THE DAY

Crafty men condemn studies, simple men admire them, and wise use them.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER