当前位置:网站首页>Sub query of multi table query_ Single row and single column
Sub query of multi table query_ Single row and single column
2022-07-24 10:05:00 【Camellia——】
-- Sub query of multi table query
-- Single row single row --> Using operators :<=...
-- Multi row single row -- Combine in( value 1, value 2, value 3)
-- Multiple rows and columns -- Put the data queried in a table --- As a virtual table-- demand : Query the information of the employee with the highest salary !
SELECT
*
FROM
emp
WHERE salary =
(SELECT
MAX(salary)
FROM
emp) ;-- demand : Query the information of employees whose salary is less than the average salary -- Using operators <,>=.=,<=....
SELECT
*
FROM
emp
WHERE salary <
(SELECT
AVG(salary)
FROM
emp) ;SELECT *FROM emp;
-- demand : Query the employee information in the finance department or the marketing department
SELECT
*
FROM
emp
WHERE emp.`dept_id` IN
(SELECT
dept.`id`
FROM
dept
WHERE NAME = ' The Marketing Department '
OR NAME = ' Finance Department ') ;
-- The third case of subquery : Multiple rows and columns
-- Query employees whose entry date is later than '2011-11-11' Then the employee information and department nameSELECT
t1.*,
-- All fields in the virtual table
t2.name -- Department table Department name
FROM
(SELECT
*
FROM
emp
WHERE join_date > '2011-11-11') t1 -- Virtual table
LEFT JOIN dept t2
ON t1.dept_id = t2.id ;-- Common links
SELECT
t1.*,
t2.name
FROM
emp t1,
dept t2
WHERE t1.join_date > '2011-11-11'
AND t1.dept_id = t2.id ;
边栏推荐
- String sort
- PHP debugging tool - socketlog installation and usage
- Arduino drive lcd1602a
- Anti shake and throttling
- Gaode map
- Financial digital transformation
- Write a simple memo using localstorage
- Implementation principle of acid in MySQL
- Color recognition of regions of interest in pictures and videos based on OpenCV
- PHP Basics - session control - cookies
猜你喜欢

二叉树、二叉树排序树的实现及遍历
![[STM32 learning] (6) use of serial port 1 (usart1)](/img/b1/430d3501a99e46958c066f7fd7eee9.png)
[STM32 learning] (6) use of serial port 1 (usart1)
![[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)](/img/6e/b7cf7a8e3296e29d61a0626e3793ea.png)
[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)
![[note] what is kernel / user space? Let's start with how the CPU runs the program](/img/b5/0ab4f2841faf3573b4502d2cd09069.png)
[note] what is kernel / user space? Let's start with how the CPU runs the program
![[C language] implementation of three versions of address book small project (including source code)](/img/3b/926001332ec05378de4c35dc28ed55.png)
[C language] implementation of three versions of address book small project (including source code)

Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
![[STM32 learning] (14) two 74HC595 controls four nixie tube displays](/img/22/c83e29bead8e6298a0a3564419022c.png)
[STM32 learning] (14) two 74HC595 controls four nixie tube displays

JMeter setting default startup Chinese

Spark Learning: how to choose different association forms and mechanisms?

What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?
随机推荐
PHP Basics - PHP magic method
缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
What happens from the input URL to the page load
【LeeCode】获取2个字符串的最长公共子串
Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
PHP Basics - PHP super global variables
Dr. water 3
Get the historical quotation data of all stocks
The concept and representation of a tree
Is CITIC Securities a safe and reliable securities firm? How to open an account?
Curse of knowledge
Spark Learning: how to choose different association forms and mechanisms?
The best time to buy and sell stocks includes handling charges (leetcode-714)
[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display
Taurus. How to upgrade and run MVC on net6 and net7
Where is the bitbucket clone address
note: expected ‘void * (***)(void ***)’ but argument is of type ‘void (*)(void *)’
PHP Basics - session control - Session
[STM32 learning] (11) STM32 Mifare_ Use of one (S50) m1s50 (read, write, key modification, control bit interpretation)
Development history of the first commercial humanoid biped robot in China