[go: up one dir, main page]

0% found this document useful (0 votes)
14 views15 pages

MySQL Simple Queries 1

Uploaded by

bollysony152
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views15 pages

MySQL Simple Queries 1

Uploaded by

bollysony152
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SIMPLE QUERIES

SELECT COMMAND

MARKS Table

1
SELECT COMMAND

• Display all the rows and all the columns from MARKS table:

SELECT COMMAND

• Display only names and marks in second subject from MARKS table:

2
SELECT COMMAND

• Display marks in third subject with heading as “MARKS 3” and name from
MARKS table:

SELECT COMMAND

• Display all columns, total of marks and average of marks from MARKS
table:

3
LIMIT CLAUSE

• Display only first 3 rows from MARKS table:

LIMIT CLAUSE

• Display only 3 records starting from 3rd row from MARKS table:

4
LIMIT CLAUSE

• Display only 3rd record from MARKS table:

LIMIT CLAUSE

• Display 15 records starting from 4th record from MARKS table:

5
WHERE CLAUSE

• Display records from MARKS table if marks 1 equal to 75:

• Display name from MARKS table if name is Ajit:

WHERE CLAUSE

• Display name from MARKS table where date of birth is 7th August, 87:

• Display roll no & name from MARKS table if marks 3 is above 70:

6
WHERE CLAUSE

• Display name & marks 2 from MARKS table where marks 2 is 60 or less:

• Display records from MARKS table if marks 1 is not equal to 75:

WHERE CLAUSE

• Display roll no, name & marks 3 from MARKS table where marks 3 is
below 75:

• Display records from MARKS table if marks 1 is more than marks 3:

7
WHERE CLAUSE

• Display records from MARKS table where total marks are above 200:

• Display records from MARKS table if avg marks is below 70:

PATTERN MATCHING (LIKE CLAUSE)


SYMBOL MEANING
_ Exactly one character.
% Any number of characters including 0.

PATTERN MEANING
A% Starting with a or A.
%d Ending with d or D.
%H% Contains h or H anywhere.
_____ Contains any 5 characters only.
__N__ Total 5 characters only, out of which 3rd character should be n or N.
_a% Second character should be a or A.
_ _a% Third character should be a or A.
%a_ _ Third last character should be a or A.
_a%e Second character should be a or A and last character e or E.

8
PATTERN MATCHING (LIKE CLAUSE)

• Display records from MARKS table where name is starting with ‘A’:

PATTERN MATCHING (LIKE CLAUSE)

• Display records from MARKS table where name is starting with Uppercase ‘A’:

• Display records from MARKS table where name is starting with Lowercase ‘A’:

9
PATTERN MATCHING (LIKE CLAUSE)

• Display records from MARKS table where names are ending with ‘Y’:

• Display records from MARKS table where names are not starting with ‘A’:

PATTERN MATCHING (LIKE CLAUSE)

• Display names and marks in 3 subjects where 2nd character of name is ‘A’:

• Display names and date of birth where 2nd last character of name is ‘A’:

10
PATTERN MATCHING (LIKE CLAUSE)

• Display records where names are exactly of 4 characters:

• Display records where names contain ‘JAY’:

PATTERN MATCHING (LIKE CLAUSE)

• Display records where second character of name is A and contains N


somewhere thereafter:

11
CONDITION WITH BETWEEN & IN

• Display records if marks 3 are between 70 and 75:

• Display name and marks 2 if marks 2 is 85 or 75 or 65:

CONDITION WITH BETWEEN & IN

• Display records where date of birth is between 10th Dec, 87 and 15th Aug, 88:

• Display records where names are between J and P:

12
CONDITION WITH BUIL-IN FUNCTIONS

• Display names where names are palindrome:

• Display records of those who are born in the year 1988:

CONDITION WITH BUIL-IN FUNCTIONS

• Display records of those who are born on 7th of any month:

• Display records of those who are born in the month of August:

13
CONDITION WITH BUIL-IN FUNCTIONS

• Display records of those who are born on Monday:

• Display records if first character of name is same as last character:

CONDITION WITH BUIL-IN FUNCTIONS

• Display records if first 2 characters of name is same as last 2 characters:

• Display records if roll number is odd:

14
CONDITION WITH BUIL-IN FUNCTIONS

• Display records if length of name is even:

15

You might also like