简体   繁体   中英

how this "and" function in sql works?

This is my query

select *
from employement 
where emp_addr = 'varanasi' and emp_addr = 'delhi'

if all the conditions separated by and are true then it will display records but here both the conditions are true still am not getting anything?

Your WHERE clause is specifying that a column in a given record simultaneously has two different values:

where emp_addr = 'varanasi' and emp_addr = 'delhi'

This is impossible, so you always get back no result set. Perhaps you intended to OR together these criteria:

where emp_addr = 'varanasi' or emp_addr = 'delhi'

Or, perhaps you want to find all groups of records which have both these addresses present:

SELECT some_col
FROM yourTable
WHERE emp_addr IN ('varanasi', 'delhi')
GROUP BY some_col
HAVING MIN(emp_addr) <> MAX(emp_addr);

使用IN

select * from employement where emp_addr in ('varanasi','delhi')

How can emp_addr='varanasi' and emp_addr='delhi'? No records will ever match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM