Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql external connection case

Shulou Source: shulou.com Published: 2022-06-01 09:25:11 11月11日 Update

# case: query the boyfriend information of the goddess whose number is > 3, list the details if any, and fill it with null.

SELECT bo.*FROM boys boRIGHT OUTER JOIN beauty bON b.`boyfriend _ id` = bo.`id`where b.`id` > 3

# case: query which city does not have a department

SELECT cityFROM locations lLEFT OUTER JOIN departments dON l.`location _ id` = d.`location _ id`where d.`department _ id`IS NULL

# case: query the employee information of the department named SAL or IT (with external connection, internal connection may have no employees and cannot be queried)

# use external connections, because there may be departments named above, but there are no employees, so fill in the employee table with null

# with an inner join, only the SAL or IT with employees will be matched, and the master table in the outer connection but not the slave table will be ignored

SELECT e.department, d.`department _ name`from departments dLEFT JOIN employees eON d.`department _ id` = e.`department _ id`where d.`department _ name`IN ('SAL','IT')

Tags: Employee inquiry case department information city goddess boyfriend Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi Huawei Shulou Technology Redmi