Author Topic: Using OR and AND together  (Read 406 times)

0 Members and 1 Guest are viewing this topic.

Offline mapleleafTopic starter

  • Enthusiast
  • Posts: 237
    • View Profile
Using OR and AND together
« on: February 27, 2010, 12:19:02 PM »
I am trying to get this to work:
SELECT FROM articles WHERE (SELECT FROM articles WHERE theme_id 10 OR FIND_IN_SET(9second_theme)) AND name 'john' AND deleted 'No'

My error is:
Operand should contain 1 column(s)

What is the way around this?
This query is dynamic in that multiple ANDS are sometimes added.

Offline ignace

  • Guru
  • Freak!
  • *
  • Posts: 5,093
  • Gender: Male
    • View Profile
Re: Using OR and AND together
« Reply #1 on: February 27, 2010, 04:17:14 PM »
SELECT * FROM articles WHERE theme_id = 10 AND name = 'John' AND deleted = 'No' AND find_in_set(9, second_theme) is not null
Developer from Belgium, Vlaams-Brabant

Offline mapleleafTopic starter

  • Enthusiast
  • Posts: 237
    • View Profile
Re: Using OR and AND together
« Reply #2 on: March 01, 2010, 01:41:43 PM »
Getting an odd error with this.
SELECT FROM articles WHERE FIND_IN_SET(32second_theme) AND deleted 'No'
//gives 16 rows

SELECT FROM articles WHERE theme_id 34 AND deleted 'No'
//gives 13 rows

SELECT FROM articles WHERE theme_id 34 OR find_in_set(32second_theme) AND deleted 'No'
//gives 32 rows because 3 of the rows have 'Yes' for deleted.
SELECT FROM articles WHERE theme_id 34 AND find_in_set(32second_themeIS NOT NULL AND deleted 'No' 
//gives 13 rows so basically excludes all the second_theme



I want to to be able to do the OR and then the AND conditions should be applied the results of the OR.
Tx


Offline mapleleafTopic starter

  • Enthusiast
  • Posts: 237
    • View Profile
Re: Using OR and AND together
« Reply #3 on: March 02, 2010, 04:09:38 PM »
SELECT * FROM articles WHERE (theme_id = 34 OR find_in_set(32, second_theme)) AND deleted = 'No';

Is what I needed.
::)