3 Replies - 917 Views - Last Post: 13 January 2009 - 09:53 AM Rate Topic: -----

#1 f150b0508  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 02-December 08

Query Select problem

Posted 12 January 2009 - 11:34 AM

Can someone help me find what I am doing wrong here? This should be simple but I am having a brain freeze.

I have a query like so:

<cfquery name="qchallenges" datasource="#Application.ds#">

SELECT * FROM newchallenges a
INNER JOIN team b on a.sentby = b.id

WHERE a.team_id = '#session.team.id#' AND a.expired = 'yes' OR a.declined = 'yes' OR a.accepted = 'yes'

</cfquery>



I have to pull results ONLY where the team_id matches the session.team.id, but also IF a.expired equals yes, a.declined equals yes, a.accepted equals yes among that team_id

I am having a problem with that stament pulling out information even if the team_id doesn't match. Example is it searches the database and found that the a.accepted field has a match so it shoes it even though the team_id doesn't match the session.team.id. I can't have that happening.

Is This A Good Question/Topic? 0
  • +

Replies To: Query Select problem

#2 CR250  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 58
  • Joined: 14-June 08

Re: Query Select problem

Posted 12 January 2009 - 12:15 PM

If any one of the OR's match it will be true. Change the OR's too AND
Was This Post Helpful? 0
  • +
  • -

#3 SleepingInChapel  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 59
  • Joined: 02-January 09

Re: Query Select problem

Posted 12 January 2009 - 02:15 PM

It looks like an order of operations problem. Try this:

<cfquery name="qchallenges" datasource="#Application.ds#">

SELECT * FROM newchallenges a
INNER JOIN team b on a.sentby = b.id

WHERE a.team_id = '#session.team.id#' AND (a.expired = 'yes' OR a.declined = 'yes' OR a.accepted = 'yes')

</cfquery>


Was This Post Helpful? 0
  • +
  • -

#4 f150b0508  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 25
  • Joined: 02-December 08

Re: Query Select problem

Posted 13 January 2009 - 09:53 AM

View PostSleepingInChapel, on 12 Jan, 2009 - 01:15 PM, said:

It looks like an order of operations problem. Try this:

<cfquery name="qchallenges" datasource="#Application.ds#">

SELECT * FROM newchallenges a
INNER JOIN team b on a.sentby = b.id

WHERE a.team_id = '#session.team.id#' AND (a.expired = 'yes' OR a.declined = 'yes' OR a.accepted = 'yes')

</cfquery>




That did it! Thanks yet again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1