For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > January 2005 > SQL Query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SQL Query
ravenslay3r@gmail.com

2005-01-22, 8:56 pm

I'm writing two query's and SQL is misinterperting the intended order
of
operations in my "WHERE" clauses. I've tried several things but can't
get
them to work.

QUERY 1
-----------

SELECT
....
....
FROM LCP_customers INNER JOIN LCP_states
ON LCP_customers.state = LCP_states.stateID
WHERE LCP_customers.pending = '0'
AND LCP_customers.status = 'contractor'
OR LCP_customers.status = 'both'";

Is supposed to do (in psydo-code for clairity):

Where ((LCP_customers.pending == '0') && (LCP_customers.status ==
'contractor
|| LCP_customers.status == 'both'));



QUERY 2
-----------

SELECT
....
....
FROM LCP_customers INNER JOIN LCP_states
ON LCP_customers.state = LCP_states.stateID
WHERE LCP_customers.pending = '0'
AND LCP_customers.state = '$state'
AND LCP_customers.status = 'contractor'
OR 'both';

Where ((LCP_customers.pending == '0') && (LCP_customers.state =
'$state') &&
(LCP_customers.status == 'contractor || LCP_customers.status ==
'both'));



Thanks for any and all help!

RavenSlay3r

Justin

2005-01-23, 3:56 am

ravenslay3r@gmail.com wrote:

> I'm writing two query's and SQL is misinterperting the intended order
> of
> operations in my "WHERE" clauses. I've tried several things but can't
> get
> them to work.
>
> QUERY 1
> -----------
>
> SELECT
> ...
> ...
> FROM LCP_customers INNER JOIN LCP_states
> ON LCP_customers.state = LCP_states.stateID
> WHERE LCP_customers.pending = '0'
> AND LCP_customers.status = 'contractor'
> OR LCP_customers.status = 'both'";
>
> Is supposed to do (in psydo-code for clairity):
>
> Where ((LCP_customers.pending == '0') && (LCP_customers.status ==
> 'contractor
> || LCP_customers.status == 'both'));
>
>
>
> QUERY 2
> -----------
>
> SELECT
> ...
> ...
> FROM LCP_customers INNER JOIN LCP_states
> ON LCP_customers.state = LCP_states.stateID
> WHERE LCP_customers.pending = '0'
> AND LCP_customers.state = '$state'
> AND LCP_customers.status = 'contractor'
> OR 'both';
>
> Where ((LCP_customers.pending == '0') && (LCP_customers.state =
> '$state') &&
> (LCP_customers.status == 'contractor || LCP_customers.status ==
> 'both'));
>
>
>
> Thanks for any and all help!
>
> RavenSlay3r
>

Looks like to me you need to use brackets

Query WHERE ( "condition 1" AND "Condition 2" ) OR "Condition 3" will
pull all records that match condition 3 and all records with both
condition 1 and 2
RavenSlay3r

2005-01-23, 8:57 pm

is that legal? I've never seen an example of an SQL query that used
brackets so I wasn't sure. I'll give it a shot!

Thanks

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com