Thread: Re: SQL "OR" Problem

Re: SQL "OR" Problem

From
Date:
first off, thanks to everyone who posted their
responses.  rather than flood the list with multiple
response, this one will address everyone (see below
for reason why).

> 1) Is the t_inspect in there for a reason? I don't
> see it referenced
> in your output or elsewhere in the where clause.
> Perhaps you are
> looking only for inspectors?

great question.  i was working on another query and i
must have gotten t_inspect stuck in my head enough
that i couldn't get it out.

> If so, an alternate
> method of writing
> this where the intent is easier to grok is:
> AND exists (select 1 from t_inspect where
> inspect_emp_id =
> t.emp.emp_id)

with the help of everyone here...  i was able to get
this to work...

SELECT DISTINCT t_emp.emp_id, t_emp.first_name || ' '
|| t_emp.last_name, t_pos.pos
FROM t_emp, t_pos
WHERE t_emp.pos_id = t_pos.pos_id
AND (t_pos.pos = 'Assembler'
OR t_pos.pos = 'Quality Inspector'
OR t_pos.pos = 'Test Technician')

leaving t_inspect in the query yielded an abbreviated
resultset so removing it (and its associated portion
of the where clause) was necessary to get accurate
results.

> 2) If an employee has several positions

in my current set up, this isn't possible.  certain
people are responsible for certain functions and there
is very little overlap.  i might decide to revisit
this constraint, though.

> or alternately
> ...t_pos.pos IN ('Assembler', 'Quality Inspector',
> 'Test Technician')

Making this change in my now working query yields the
exact same result - success.

> > 2. if an employee is a Qaulity Inspector...
> This line gave my best chuckle of the day :).

i have to admit, that *IS* funny...  but the day isn't
over yet and i may not be finished posting!  -lol-

> Thanks.
>
> Cheers,
> Steve

no, no.  thank you and everyone else who helped me
with this problem.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Re: SQL "OR" Problem - Small Update

From
Date:
> with the help of everyone here...  i was able to get
> this to work...
>
> SELECT DISTINCT t_emp.emp_id, t_emp.first_name || '
> '
> || t_emp.last_name, t_pos.pos
> FROM t_emp, t_pos
> WHERE t_emp.pos_id = t_pos.pos_id
> AND (t_pos.pos = 'Assembler'
> OR t_pos.pos = 'Quality Inspector'
> OR t_pos.pos = 'Test Technician')

...until i tried to stuff the resultset into an array.
 I received the following error.

Call to a member function on a non-object

so i ditched the DISTINCT and the results were still
as expected and i can put the resultset into an array.

the "final answer" code (for the moment, anyway -lol-)
is:

SELECT t_employee.employee_id, t_employee.first_name
|| ' ' || t_employee.last_name, t_position.position
FROM t_employee, t_position
WHERE t_employee.position_id = t_position.position_id
AND t_position.position IN ('Assembler', 'Quality
Inspector', 'Test Technician')

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com