डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

Full Stack Web Development with Laravel

Full Stack Web Development with Laravel

Affiliate Program

Affiliate Program

MYSQL LIMIT LIKE IN BETWEEN Operators

For these operators and keywords, we will take this given table as an example.

Table: posts
id title post
1 What is a computer? Electronic machine
2 An input device Keyboard
3 WWW stands for World wide web


LIMIT

LIMIT specifies how many records will fetch in a query.

Display only one record after record that has id 2.

SELECT * FROM posts LIMIT 2, 1;

WHERE the first number defines the skip and the second number defines how many records will display.

Table: posts
id title post
3 WWW stands for World wide web

LIKE

Like operator is used to search any pattern in records.

There are wildcards used with LIKE keywords.

  • % - Represents zero, one, and multiple matched characters
  • _ - underscore represents one character.

Find all those posts whose title start with "w"

SELECT * FROM posts WHERE title LIKE 'w%'
Table: posts
id title post
1 What is a computer? Electronic machine
3 WWW stands for World wide web


Find all those posts whose title end with "r"

SELECT * FROM posts WHERE title LIKE '%r';
Table: posts
id title post
3 WWW stands for World wide web

Find all those posts whose titles contain "i"

SELECT * FROM posts WHERE title LIKE '%i%';
Table: posts
id title post
1 What is a computer? Electronic machine
2 An input device Keyboard

Find all those posts whose title start with 'a' and contain 2 characters

SELECT * FROM posts WHERE title LIKE 'a_%';
Table: posts
id title post
2 An input device Keyboard

For IN and BETWEEN operators, the given table will be taken as an example.

Table: products
id product_name price qty
1 UPS 3000 2
2 PEN 100 2
3 MOUSE 400 1
4 SPEAKER 5000 2

 

In Operator

It is a shorthand for the OR operator, it allows to use of multiple values in the WHERE clause.

Fetch only those records which have id 1,2,4.

SELECT * FROM products WHERE id IN(1, 2, 4);
Table: products
id product_name price qty
1 UPS 3000 2
2 PEN 100 2
4 SPEAKER 5000 2

BETWEEN Operator

When we want to fetch all those records whose price between in a given range.

Fetch all those records whose prices are between 1000 to 5000.

SELECT * FROM products WHERE price BETWEEN 1000 AND 5000;
Table: products
id product_name price qty
1 UPS 3000 2
4 SPEAKER 5000 2

 

© 2016 - 2023, All Rights are Reserved.