MySQL Database Queries for Student Information

undefined
 
 
There exists  table STUDENTS in the database COLLEGE
    Write My SQL queries for the following :
Display the contents  of the table STUDENTS.
SELECT  *  FROM  STUDENTS;
Display the name and class  of the all the rows of  table STUDENTS.
SELECT  S_NAME, CLASS
    FROM  STUDENTS;
Display the name  &  class of  all the rows of the table  in alphabetical order of
the  names.
SELECT  S_NAME, CLASS
FROM  STUDENTS
ORDER BY S_NAME;
Display name & class  of all the STUDENTS separated by a comma with the
heading student details.
SELECT  CONCAT(S_NAME, ‘ , ’,CLASS) AS ‘Student  Details’
    FROM  STUDENTS;
 
Display roll no &  name  for those students whose    roll no  is greater
than 2
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE RNO>2;
Display roll no &   name  for those students whose    roll no  is greater
than  or equal to 2  but less than or equal to 6
SELECT   RNO, S_NAME
 
FROM  STUDENTS
WHERE RNO  BETWEEN 2 AND 6;
Display roll no &   name  for those students whose    roll no  is less
than 2  but greater than 6
SELECT   RNO, S_NAME
FROM  STUDENTS
    WHERE RNO  NOT BETWEEN 2 AND 6;
 
Display roll no &   name  for those students whose    roll no  is greater
than 2  but less than 6 in alphabetical order of names
SELECT   RNO, S_NAME
 
FROM  STUDENTS
WHERE RNO  BETWEEN 2 AND 6
ORDER BY S_NAME ;
 Display the roll no & name of all the students whose roll no is  2 or 4
or 5.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE RNO  IN (2,4,5);
Display the id & name  of all the students whose roll no is  not 2 or 4
or 5.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE RNO NOT  IN (2,4,5);
 
Display the roll no & name  of all the students whose names have the letter 
a
 in
the end.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘%a’;
 Display the roll no & name  of students whose names starts with  the letter 
a
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘a%’;
 View the roll no & name  of  the students whose names have the letter 
a
.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘%a%’;
 Display the roll no & name  of all the students whose names starts & ends with
letter 
a
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘a%a’;
 
Display the roll no & name  of all the students whose name has letter 
a
in the fifth place.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘____a%’;
 Display the roll no & name  of all the students whose name starts with
letter 
a
  or starts with letter 
v
.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘a%’  OR  S_NAME LIKE ‘v%’;
 Display the roll no & name  of all the students whose name have
letter 
a
  and  letter  
j
  in it.
SELECT   RNO, S_NAME
FROM  STUDENTS
WHERE S_NAME LIKE ‘%a%’  AND  S_NAME LIKE ‘%j%’;
Slide Note
Embed
Share

Learn how to query a MySQL database to display student information including names, classes, and roll numbers. Explore various SQL statements to retrieve specific data such as sorting alphabetically, filtering by roll numbers, and searching for specific name patterns

  • Database
  • MySQL
  • SQL queries
  • Student information
  • Data retrieval

Uploaded on Feb 27, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. MYSQL PRACTICALS - 2

  2. There exists table STUDENTS in the database COLLEGE Write My SQL queries for the following : Display the contents of the table STUDENTS. SELECT * FROM STUDENTS; Display the name and class of the all the rows of table STUDENTS. SELECT S_NAME, CLASS FROM STUDENTS; Display the name & class of all the rows of the table in alphabetical order of the names. SELECT S_NAME, CLASS FROM STUDENTS ORDER BY S_NAME; Display name & class of all the STUDENTS separated by a comma with the heading student details. SELECT CONCAT(S_NAME, , ,CLASS) AS Student Details FROM STUDENTS;

  3. Display roll no & name for those students whose roll no is greater than 2 SELECT RNO, S_NAME FROM STUDENTS WHERE RNO>2; Display roll no & name for those students whose roll no is greater than or equal to 2 but less than or equal to 6 SELECT RNO, S_NAME FROM STUDENTS WHERE RNO BETWEEN 2 AND 6; Display roll no & name for those students whose roll no is less than 2 but greater than 6 SELECT RNO, S_NAME FROM STUDENTS WHERE RNO NOT BETWEEN 2 AND 6;

  4. Display roll no & name for those students whose roll no is greater than 2 but less than 6 in alphabetical order of names SELECT RNO, S_NAME FROM STUDENTS WHERE RNO BETWEEN 2 AND 6 ORDER BY S_NAME ; Display the roll no & name of all the students whose roll no is 2 or 4 or 5. SELECT RNO, S_NAME FROM STUDENTS WHERE RNO IN (2,4,5); Display the id & name of all the students whose roll no is not 2 or 4 or 5. SELECT RNO, S_NAME FROM STUDENTS WHERE RNO NOT IN (2,4,5);

  5. Display the roll no & name of all the students whose names have the letter a in the end. SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE %a ; Display the roll no & name of students whose names starts with the letter a SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE a% ; View the roll no & name of the students whose names have the letter a. SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE %a% ; Display the roll no & name of all the students whose names starts & ends with letter a SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE a%a ;

  6. Display the roll no & name of all the students whose name has letter a in the fifth place. SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE ____a% ; Display the roll no & name of all the students whose name starts with letter a or starts with letter v. SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE a% OR S_NAME LIKE v% ; Display the roll no & name of all the students whose name have letter a and letter j in it. SELECT RNO, S_NAME FROM STUDENTS WHERE S_NAME LIKE %a% AND S_NAME LIKE %j% ;

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#