0% found this document useful (0 votes)
83 views

Querying and Filtering Data in Mysql Table (Extended)

This document discusses various techniques for querying and filtering data in MySQL tables using LIMIT, ORDER BY, ASC, DESC, BETWEEN, NOT BETWEEN, IN, NOT IN, LIKE, and handling NULL values. It provides examples of selecting the top 3 records, ordering results descending by salary, finding values within a range, pattern matching, and checking for NULL. Date formatting and type conversion using CAST is also covered.

Uploaded by

Babe Sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Querying and Filtering Data in Mysql Table (Extended)

This document discusses various techniques for querying and filtering data in MySQL tables using LIMIT, ORDER BY, ASC, DESC, BETWEEN, NOT BETWEEN, IN, NOT IN, LIKE, and handling NULL values. It provides examples of selecting the top 3 records, ordering results descending by salary, finding values within a range, pattern matching, and checking for NULL. Date formatting and type conversion using CAST is also covered.

Uploaded by

Babe Sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Querying and Filtering data in

MySQL Table (Extended)


Using limit (ORDER BY, ASC, DESC)

Create a table employees


Using limit (ORDER BY, ASC, DESC)
• Select the first 3 customers

• Select all attributes

• Find 4 records without first 2 records


Using limit (ORDER BY, ASC, DESC)
• Using MySQL LIMIT to get the highest 3 values

• Using MySQL ORDER BY and DESC to get the Descending Order salary

• Using MySQL LIMIT to get the highest values


• Using MySQL LIMIT to get the highest 2nd values

• Using MySQL LIMIT to get the lowest 3 values

• Using MySQL ORDER BY and ASC to get the Ascending Order salary
Between, Not Between In, Not In
• MySQL IN examples Like OR operator

• MySQL NOT IN examples

• MySQL BETWEEN examples

• SELECT fname, lname


FROM employee
WHERE salary>= 20000 AND salary <=43000;
• MySQL NOT BETWEEN to get exact values

• MySQL BETWEEN with dates example

• View date with different format


select DATE_FORMAT(BirthDate, '%M %D %Y') AS new_style from students

The CAST() function converts a value of any type into a value that has a specified type.
The target type can be any one of the following types:
 BINARY, CHAR, DATE, DATETIME, TIME,DECIMAL, SIGNED, UNSIGNED .
Date Format
%Y Year as a numeric, 4-digit
value
%y Year as a numeric, 2-digit
value

%W Weekday name in full (Sunday


to Saturday)
%w Day of the week where
Sunday=0 and Saturday=6

%M Month name in full (January


to December)
%m Month name as a numeric
value (00 to 12)

%D Day of the month as a


numeric value, followed by
suffix (1st, 2nd, 3rd, ...)
%d Day of the month as a
numeric value (01 to 31)
Using MySQL LIKE operator to select
data based on patterns
• MySQL LIKE examples
• The percentage ( % ) wildcard allows you to
match any string of zero or more characters.
• The underscore ( _ ) wildcard allows you to
match any single character.
• Find employees name who has first name starting with ‘m’

• Find employees name who has first name ending with ‘r’

• Find employees name who has first name contains ‘bb’


• Finds any values that have “u" in the second position
• Example-1

• select * from students where FirstName like '_u%'

• Example-2
• Finds any values that start with “m" and are at least 3 characters in length
• select * from students where FirstName like 'm__%'
• MySQL LIKE operator with NOT operator
• Example-1:

• select * from students where FirstName not like 'm__%'

• Example-2
• Checking NULL values

You might also like