Re: SQL "OR" Problem
| От | Tom Lane |
|---|---|
| Тема | Re: SQL "OR" Problem |
| Дата | |
| Msg-id | 22514.1125088067@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | SQL "OR" Problem (<operationsengineer1@yahoo.com>) |
| Список | pgsql-novice |
<operationsengineer1@yahoo.com> writes:
> WHERE t_emp.pos_id = t_pos.pos_id
> AND t_inspect.inspect_emp_id = t_emp.emp_id
> AND t_pos.pos = 'Assembler'
> OR t_pos.pos = 'Quality Inspector'
> OR t_pos.pos = 'Test Technician'
You probably want some parentheses with that:
WHERE t_emp.pos_id = t_pos.pos_id
AND t_inspect.inspect_emp_id = t_emp.emp_id
AND (t_pos.pos = 'Assembler'
OR t_pos.pos = 'Quality Inspector'
OR t_pos.pos = 'Test Technician')
I believe AND binds more tightly than OR by default, so your original
means
WHERE (t_emp.pos_id = t_pos.pos_id
AND t_inspect.inspect_emp_id = t_emp.emp_id
AND t_pos.pos = 'Assembler')
OR t_pos.pos = 'Quality Inspector'
OR t_pos.pos = 'Test Technician'
which is unlikely to be what you want.
regards, tom lane
В списке pgsql-novice по дате отправления: