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

Alibaba Cloud Server Linux System Builds Tomcat to Deploy Web Project

I divide the whole process into four steps: Downl...

How to use mysql index merge

Index merging is an intelligent algorithm provide...

Detailed explanation of Linux commands sort, uniq, tr tools

Sort Tool The Linux sort command is used to sort ...

A brief discussion on the lazy loading attribute pattern in JavaScript

Table of contents 1. Introduction 2. On-demand at...

Detailed Analysis of or, in, union and Index Optimization in MySQL

This article originated from the homework assignm...

Tutorial on building a zookeeper server on Windows

Installation & Configuration The official web...

How to import Chinese data into csv in Navicat for SQLite

This article shares with you the specific method ...

Implementation of positioning CSS child elements relative to parent elements

Solution Add position:relative to the parent elem...

Summary of basic operations for MySQL beginners

Library Operations Query 1.SHOW DATABASE; ----Que...

Summary of several replication methods for MySQL master-slave replication

Asynchronous replication MySQL replication is asy...

Bootstrap 3.0 study notes for beginners

As the first article of this study note, we will ...

Example of how to reference environment variables in Docker Compose

In a project, you often need to use environment v...