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 6634815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:58:27+00:00 2026-05-25T22:58:27+00:00

I m stuck in a situation where I needed (column1 and column2) or (column1

  • 0

I m stuck in a situation where I needed (column1 and column2) or (column1 or column3) from a table. So i implemented it as

    select * from mytable 
    where column1=x and (column2=y or column3=z)

But it fetches me some unneccesory rows and by implementing as

    select * from mytable 
    where (column1=x and column2=y) or (column1=x and column3=z)

It gives the result but i couldn’t understand the diff between the two…please suggest

EDIT (added details)

Below I have explained my situation, Please check this,

Let me elaborate my situation :::

I have a table, say clientdetails(int id, var firstname, var mobileno, var landlineno) and I need to fetch those entries fetching values having unique (firstname and mobileno), or (firstname and landlineno). Either of the two mobileno or landlineno is mandatory.

so i wrote a query…

select id
from clientdetails 
where firstname = 'pooja' 
and (mobileno = mn or landlineno= ln )   
and mobileno  REGEXP '^[0-9]+$' 
and landlineno REGEXP '^[0-9]+$'"

Now ln or mn can be anything and say ”. Since there are many instances where the firstname is “pooja” without a landlineno. So it fetches that entries too which has no landlineno but different mobileno..

When I use the following query

select id
from clientdetails 
where (firstname = 'pooja' and mobileno = mn)
or (firstname = 'pooja' and landlineno= '' )
and mobileno REGEXP '^[0-9]+$'
and landlineno REGEXP '^[0-9]+$'"

It fetches me the required rows.

Please explain me the execution format of these queries

  • 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-05-25T22:58:28+00:00Added an answer on May 25, 2026 at 10:58 pm

    So as Alnitak pointed out in comments, There shouldn’t be any difference – given three boolean variables

    A, B, C, then A & (B | C) == (A & B) | (A & C)
    

    Well, I have tested both queries with simple example below both queries gives same result.

       create table emp_temp(id smallint(5),fname varchar(10),lname varchar(10));
    
        insert into emp_temp values (1,'jon','kam'),(2,'ish','dalviv'),(3,'ctn','gado'),
        (4,'jin','jain'),(5,'niraj','yadav');
    
        select * from emp_temp;
    
        mysql> select * from emp_temp;
        +------+-------+--------+
        | id   | fname | lname  |
        +------+-------+--------+
        |    1 | jon   | kam    |
        |    2 | ish   | dalviv |
        |    3 | ctn   | gado   |
        |    4 | jin   | jain   |
        |    5 | niraj | yadav  |
        +------+-------+--------+
        5 rows in set (0.00 sec)
    
        Now comparing your two queries.
    
        select * from mytable 
        where column1=x and (column2=y or column3=z)
    
        select * from mytable 
        where (column1=x and column2=y) or (column1=x and column3=z)
    
        Consider
    
        column1 is id
        column2 is fname
        column3 is lname
    
        mysql> select * from emp_temp
            -> where id=1 and (fname='jon' or lname='yadav');
        +------+-------+-------+
        | id   | fname | lname |
        +------+-------+-------+
        |    1 | jon   | kam   |
        +------+-------+-------+
        1 row in set (0.01 sec)
    
    
        mysql> select * from emp_temp 
            -> where (id=1 and fname='jon') or ( id=1 and lname='yadav');
    
        +------+-------+-------+
        | id   | fname | lname |
        +------+-------+-------+
        |    1 | jon   | kam   |
        +------+-------+-------+
        1 row in set (0.01 sec)
    
        Both queries produces the same result.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ASP.NET MVC 2 and stuck with the situation when needed to store
I am stuck in a situation from which I am finding no solution. Let
im stuck in a situation where i am switching from activity 1 to activity
I am stuck in weird situation. I want to upload photo from my iPad
I am stuck in a strange situation , i am getting data from the
I am working on some academic task and I'm stuck. The situation is as
I'm basically stuck in a situation where I need a bunch of div's with
I am new to iPhone programming, and stuck in a situation. The situation is
I just stuck in a very simple situation bt couldnt help myself.My question is
Been stuck on this for ages. Currently learning Django and done some bits on

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.