Essential conditional query statements for MySQL database

Essential conditional query statements for MySQL database

1. Basic grammar

SELECT
	Query list FROM
	Table name WHERE
	filter expression;

2. Filter by conditional expression

Conditional operators: >,<,=,!=,<>,>=,<=
The conditional operator cannot evaluate to null .

#Filter all information of employees whose salary is greater than 12000 in the employees table SELECT
	*
FROM
	employees
WHERE
	salary>12000;

3. Filter by logical expression

Logical operators: &&,||,!,and,or,not
Used to connect conditional expressions

SELECT
	*
FROM
	employees
WHERE
	salary>12000 AND salary<16000;

4. Fuzzy query

Keywords: like,between and,in,is null,is not null

①like: Usually used with wildcards. Wildcards: % represents any number of characters, _ represents an arbitrary character. If the wildcard itself needs to be used, use the \ escape character, such as \_ .

#Query all information of employees whose second letter of name is aSELECT
	*
FROM
	employees
WHERE
	last_name LIKE '_a%';

②between and: contains two critical values. Note that the order of the two critical values ​​cannot be reversed.

SELECT
	*
FROM
	employees
WHERE
	salary BETWEEN 10000 AND 16000;

③in: Determine whether the value of a field belongs to an item in the in list. Wildcards are not supported.

#Query all information of employees with job numbers SA_MAN and PR_REPSELECT
	*
FROM
	employees
WHERE
	job_id IN('SA_MAN','PR_REP');

④is null (is not null): is empty and not empty

#Query all information of employees without bonus SELECT
	*
FROM
	employees
WHERE
	commission_pct IS NULL;

5. Safety is equal to

Symbol: <=> means equal, which can replace is , =

SELECT
	*
FROM
	employees
WHERE
	commission_pct <=> NULL;

This is the end of this article about the necessary conditional query statements for MySQL database. For more relevant MySQL conditional query content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL learning prerequisites for querying data
  • MySQL conditional query and or usage and priority example analysis
  • MySql multi-condition query statement with OR keyword
  • Mysql multi-condition query statement with And keyword
  • How to use case when statement in MySQL to implement multi-condition query
  • A comprehensive summary of common operations of MySQL conditional query statements

<<:  Detailed explanation of the use of title tags and paragraph tags in XHTML

>>:  How to make a website front end elegant and attractive to users

Recommend

Vue two same-level components to achieve value transfer

Vue components are connected, so it is inevitable...

Detailed explanation of MySQL 30 military rules

1. Basic Specifications (1) InnoDB storage engine...

MySQL paging performance exploration

Several common paging methods: 1. Escalator metho...

MariaDB-server installation of MySQL series

Table of contents Tutorial Series 1. Install Mari...

Solution to nacos not being able to connect to mysql

reason The mysql version that nacos's pom dep...

A complete guide to some uncommon but useful CSS attribute operations

1. Custom text selection ::selection { background...

Using Vue to implement timer function

This article example shares the specific code of ...

Solution to the ineffectiveness of flex layout width in css3

Two-column layout is often used in projects. Ther...

Detailed steps to delete environment variables in Linux

How to delete environment variables in Linux? Use...

Solve the MySQL 5.7.9 version sql_mode=only_full_group_by problem

MySQL 5.7.9 version sql_mode=only_full_group_by i...

What does the legendary VUE syntax sugar do?

Table of contents 1. What is syntactic sugar? 2. ...

Example of adding and deleting range partitions in MySQL 5.5

introduce RANGE partitioning is based on a given ...

jQuery to achieve the barrage effect case

This article shares the specific code of jQuery t...

Centos7.3 automatically starts or executes specified commands when booting

In centos7, the permissions of the /etc/rc.d/rc.l...