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

  • SEARCH
  • Home
  • 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 7862419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:07:21+00:00 2026-06-02T23:07:21+00:00

I need to query a table with a filtering condition on three columns: select

  • 0

I need to query a table with a filtering condition on three columns:

select * 
from table a 
where a.order = car 
and a.color !=red 
or a.automatic !=auto

This just checks the first conditions and ignores the second one.

I just can’t get my head around it 🙁

  • 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-02T23:07:23+00:00Added an answer on June 2, 2026 at 11:07 pm

    Its not clear from your question but all you probably need is to wrap parens around your OR condition

    Given this following table and rows

    CREATE TABLE table_a 
        (
         id int primary key, 
         a_order varchar2(20), 
         color varchar2(40),
         automatic varchar2(10)
        )
    
    /
    
    
    INSERT INTO table_a VALUES (1,'car','red','auto')     /
    INSERT INTO table_a VALUES (2,'car','red','manual')   /
    INSERT INTO table_a VALUES (3,'car','blue','auto')    /
    INSERT INTO table_a VALUES (4,'car','blue','manual') /
    INSERT INTO table_a VALUES (5,'truck','red','auto')   /
    INSERT INTO table_a VALUES (6,'truck','red','manual') /
    INSERT INTO table_a VALUES (7,'truck','blue','auto') /
    INSERT INTO table_a VALUES (8,'truck','blue','manual') /
    

    This select statement will return records 2, 3 and 4 since they are all cars and are either blue or manual

    SELECT * 
    FROM   table_a a 
    WHERE  a.a_order = 'car' 
           AND ( a.color != 'red' 
                  OR a.automatic != 'auto' ) 
    

    Demo

    Another option is to do the following using De Morgan’s law “The negation of a disjunction is the conjunction of the negations.”

    SELECT * 
    FROM   table_a a 
    WHERE  a.a_order = 'car' 
        AND NOT ( a.color = 'red' 
                 AND a.automatic = 'auto' ) 
    

    Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three table I need to query table 1,2 and 3 and select
I need to select rows from database table using filtering by xml-type column. table
need help/guide for sql select query, I have 2 table stock and stock_history, in
I need a query that will return a table where each column is the
I need a query which can do the following operation. I have a table
I have a rather large table which I need to query for a reporting
I need to write a query that will go through a table, find duplicate
I need to speed up a query. Is an index table what I'm looking
I need a little help brainstorming on a query. I have a sales table
I have a query that does what i want joining table but i need

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.