Skip to content

Latest commit

 

History

History
119 lines (64 loc) · 2.32 KB

Lecture2.md

File metadata and controls

119 lines (64 loc) · 2.32 KB

SELECT <Column name 1>, <Column name 2>.... FROM

;

SELECT * FROM

;

SELECT * FROM

WHERE <Column name 1> =/</> "Value 1";

Sample Command - SELECT * FROM students2 -> WHERE Score = 50;

SELECT * FROM

Where LIKE "%String%"

Sample Command -

SELECT * FROM students2 Where Name LIKE "Sarthak Jain"; SELECT * FROM students2 Where Name LIKE "%Jain";

SELECT * FROM

Where LIKE "_String%";

Sample Command -

SELECT * FROM students2 Where Name LIKE "_e%"; SELECT * FROM students2 Where Name LIKE "%";

SELECT * FROM

WHERE {Comparisson} AND / OR {Comparisson};

// Comparisson -> <column name 1> = -> <column name 2> >/ < />= /<=

Sample Command - SELECT * FROM students2 WHERE MaritalStatus = "Married" AND Score > 50;

SELECT * FROM students2 WHERE MaritalStatus = "Single" OR Score = 60;

SELECT * FROM students2 WHERE NOT =

Sample Command - SELECT * FROM students2 WHERE NOT Score = 60;

SELECT * FROM students2 WHERE NOT MaritalStatus = "Single";

SELECT * FROM students2 WHERE (MaritalStatus = "Single" AND Score = 70) OR (MaritalStatus = "NA" OR Score = 80);

SELECT * FROM

WHERE {Comparisson} ORDER BY ;

Sample Command - SELECT * FROM students2 ORDER BY Name; SELECT * FROM students2 ORDER BY MaritalStatus; SELECT * FROM students2 ORDER BY MaritalStatus, Name;

SELECT * FROM

Where { Comparisson} ORDER BY ASC/ DESC; //Ascending or Descending order

Sample Command - SELECT * FROM students2 Where Score >50 ORDER BY Name DESC;

SELECT * FROM students2 ORDER BY Score DESC, Name ASC; SELECT * FROM students2 ORDER BY Score DESC, DOB DESC;

SELECT * FROM

WHERE {comparisson}... ORDER BY ... LIMIT ;

Sample Command -

SELECT * FROM students2 ORDER BY Score DESC LIMIT 3;

SELECT * FROM

WHERE {comparisson}.. ORDER BY ... LIMIT OFFSET ;

Sample command - SELECT * FROM students2 ORDER BY Score DESC LIMIT 1 OFFSET 3;

SELECT * FROM students2 ORDER BY Score DESC LIMIT 3,1; // Same query for 4th rank

SELECT * FROM

WHERE {comparisson}.. ORDER BY ... LIMIT , ; //another way of writing