Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9282641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:25:39+00:00 2026-06-18T18:25:39+00:00

I am developing a flowerbed planting system, and have written an SQL statement which

  • 0

I am developing a flowerbed planting system, and have written an SQL statement which queries 8 tables in order to return a list of suitable plants.

Table structure: http://pastebin.com/0DUYQis1 [outputted from phpmyadmin]

Example Data: http://gyazo.com/13dad0b3370b5053dbcad2a32013a54a / http://gyazo.com/1bd313adb3e8ccd01354c979e69fd059

SQL Statement:

SELECT Plant.Plant_ID, Plant.Plant_Quantity, Plant.Plant_Price, Plant.Plant_Description, Plant.Plant_Latin_Name, Plant.Plant_Common_Name, Plant.Plant_Height, Plant.Plant_Spread, Plant.Plant_Type, Plant.Plant_Family, Plant.Plant_Picture, Plant_Aspect.Plant_Aspect, Plant_Flower_Colour.Plant_Flower_Colour, Plant_Flower_Colour.Plant_Season, Plant_Foliage_Colour.Plant_Foliage_Colour, Plant_Foliage_Colour.Plant_Season, Plant_Moisture.Plant_Moisture, Plant_Soil_PH.Plant_Soil_PH, Plant_Soil_Type.Plant_Soil_Type, Plant_Sun_Type.Plant_Sun_Type 

FROM Plant 

INNER JOIN Plant_Aspect ON Plant.Plant_ID = Plant_Aspect.Plant_ID 
INNER JOIN Plant_Flower_Colour ON Plant.Plant_ID = Plant_Flower_Colour.Plant_ID 
INNER JOIN Plant_Foliage_Colour ON Plant.Plant_ID = Plant_Foliage_Colour.Plant_ID 
INNER JOIN Plant_Moisture ON Plant.Plant_ID = Plant_Moisture.Plant_ID
INNER JOIN Plant_Soil_PH ON Plant.Plant_ID = Plant_Soil_PH.Plant_ID 
INNER JOIN Plant_Soil_Type ON Plant.Plant_ID = Plant_Soil_Type.Plant_ID 
INNER JOIN Plant_Sun_Type ON Plant.Plant_ID = Plant_Sun_Type.Plant_ID 

WHERE Plant_Aspect.Plant_Aspect = 'East-facing'
OR Plant_Aspect.Plant_Aspect = 'Any'
AND Plant_Soil_Type.Plant_Soil_Type = 'Sand' 
OR Plant_Soil_Type.Plant_Soil_Type = 'Any'
AND Plant_Moisture.Plant_Moisture = 'Well-drained' 
OR Plant_Moisture.Plant_Moisture = 'Any'
AND Plant_Soil_PH.Plant_Soil_PH = 'Acid'
OR Plant_Soil_PH.Plant_Soil_PH = 'Any'
AND Plant_Foliage_Colour.Plant_Foliage_Colour = 'Green'
AND Plant_Foliage_Colour.Plant_Season = 'Winter'
OR Plant_Foliage_Colour.Plant_Season = 'Any'
AND Plant_Flower_Colour.Plant_Flower_Colour = 'Orange'
AND Plant_Flower_Colour.Plant_Season = 'Winter'
OR Plant_Flower_Colour.Plant_Season = 'Any'

GROUP BY Plant_ID;

I was expecting the query to return only those plants that have a record matching the search criteria, ie. only those plants that can be planted in the season ‘Winter’ or ‘Any’, but instead it is returning plants it shouldn’t be.

For example: http://gyazo.com/d2ca989fc6def79854a1d9b11e4bc310 – Plant_ID: 1 contains only one record in the Plant_Flower_Colour table – Dark Blue during Spring. Why is it this record has been returned? It’s as if the trailing ANDs and ORs are being ignored.

Any help would be much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:25:41+00:00Added an answer on June 18, 2026 at 6:25 pm

    An alternative form for the and/or would be to use IN() clauses, which is easyer to read, easyer to edit and less accident-prone.

    WHERE Plant_Aspect.Plant_Aspect IN( 'East-facing' , 'Any' )
    AND Plant_Soil_Type.Plant_Soil_Type IN( 'Sand' , 'Any' )
    AND Plant_Moisture.Plant_Moisture IN( 'Well-drained' , 'Any' )
    AND Plant_Soil_PH.Plant_Soil_PH IN( 'Acid' , 'Any' )
    AND Plant_Foliage_Colour.Plant_Foliage_Colour IN( 'Green' )
    AND Plant_Foliage_Colour.Plant_Season IN( 'Winter' , 'Any' )
    AND Plant_Flower_Colour.Plant_Flower_Colour IN( 'Orange' )
    AND Plant_Flower_Colour.Plant_Season IN( 'Winter' , 'Any' )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

developing a web application using java. I have SQL queries with more than 40
Developing an application, In which I have many user's account_id(skype id), Now what I
Developing a brand new schema/app which uses hibernate to create tables from pojo's. My
Developing a Django web app, I have a list of packages I need to
Developing for Android 2.3, I have a question regarding layouts. I use a vertival
Developing a project of mine I realize I have a need for some level
For developing an devices monitor system, I am using a InetAdress isReachable method to
Developing a program which uses hash map with integer as keys and objects as
Developing for iPhone, I have a collection of points that I need to make
Developing on the blackberry (OS 7.0) and I have an extended Vertical Field manager

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.