Home > Database > Mysql Tutorial > mysql联合查询中and or的使用_MySQL

mysql联合查询中and or的使用_MySQL

WBOY
Release: 2016-06-01 13:46:01
Original
1090 people have browsed it

bitsCN.com

需求环境:

功能:简历搜索

需求:求职类型中可以选择全职、兼职、临时工、实习生一种或者多种,但是一份简历又只有一种,要将满足任一条件的简历全部列出来

障碍:or 的任一条件为TRUE即停止判断,and条件取交集

 

SELECT 

t_person_info.personid, 

t_person_info.personname, 

t_person_info.sex, 

t_person_edu.education, 

t_person_edu.school, 

t_person_edu.`subject`, 

t_person_edu.`to` 

FROM 

t_person_info 

LEFT JOIN t_person_edu ON t_person_edu.personid = t_person_info.personid 

WHERE 1=1 

 

AND (type = 3 OR type = 1) 

AND (company = 222 OR company = '湖北指数')

看14行和15行,会优先执行括号里面的或条件,然后执行括号左侧最近的条件,适合同一字段取并集

本文出自 “金色猪子的PHP成长之路” 博客

bitsCN.com
Related labels:
CV
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template