filmov
tv
SQL || SQL Interview Questions And Answers || EXAMPLES

Показать описание
. How to fetch common records from two tables?
Common records result set can be achieved by -.
1 Select studentID from student. strong INTERSECT /strongSelect StudentID from Exam
47. How to fetch alternate records from a table?
Records can be fetched for both Odd and Even row numbers -.
To display even numbers-.
MySQL
1 Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
To display odd numbers-.
MySQL
1 Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
from (Select rowno, studentId from student) where mod(rowno,2)=1.[/sql]
48. How to select unique records from a table?
Select unique records from a table by using DISTINCT keyword.
1 Select DISTINCT StudentID, StudentName from Student.
49. What is the command used to fetch first 5 characters of the string?
There are many ways to fetch first 5 characters of the string -.
MySQL
1 Select SUBSTRING(StudentName,1,5) as studentname from student
MySQL
1 Select RIGHT(Studentname,5) as studentname from student
50. Which operator is used in query for pattern matching?
LIKE operator is used for pattern matching, and it can be used as -.
1. % – Matches zero or more characters.
2. _(Underscore) – Matching exactly one character.
Example -.
MySQL
1 Select * from Student where studentname like ‘a%’
1 Select * from Student where studentname like ‘ami_’
Common records result set can be achieved by -.
1 Select studentID from student. strong INTERSECT /strongSelect StudentID from Exam
47. How to fetch alternate records from a table?
Records can be fetched for both Odd and Even row numbers -.
To display even numbers-.
MySQL
1 Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0
To display odd numbers-.
MySQL
1 Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1
from (Select rowno, studentId from student) where mod(rowno,2)=1.[/sql]
48. How to select unique records from a table?
Select unique records from a table by using DISTINCT keyword.
1 Select DISTINCT StudentID, StudentName from Student.
49. What is the command used to fetch first 5 characters of the string?
There are many ways to fetch first 5 characters of the string -.
MySQL
1 Select SUBSTRING(StudentName,1,5) as studentname from student
MySQL
1 Select RIGHT(Studentname,5) as studentname from student
50. Which operator is used in query for pattern matching?
LIKE operator is used for pattern matching, and it can be used as -.
1. % – Matches zero or more characters.
2. _(Underscore) – Matching exactly one character.
Example -.
MySQL
1 Select * from Student where studentname like ‘a%’
1 Select * from Student where studentname like ‘ami_’