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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:08:44+00:00 2026-05-22T21:08:44+00:00

What is the difference between the following 2 queries? (They both produce the same

  • 0

What is the difference between the following 2 queries? (They both produce the same results)

select *
from (
  select * from (
           select *
           from phppos_items
           where name like 'AB10LA2%' and deleted = 0
           order by `name` limit 16
           ) t
  union
  select * from (
           select *
           from phppos_items
           where item_number like 'AB10LA2%' and deleted = 0
           order by `name` limit 16
           ) t
  union
  select * from (
           select *
           from phppos_items
           where category like 'AB10LA2%' and deleted = 0
           order by `name` limit 16
           ) t
  ) as top_rows
order by `name` limit 16

vs

select *
from (
           (select *
           from phppos_items
           where name like 'AB10LA2%' and deleted = 0
           order by `name` limit 16)
  union
           (select *
           from phppos_items
           where item_number like 'AB10LA2%' and deleted = 0
           order by `name` limit 16)
  union
           (select *
           from phppos_items
           where category like 'AB10LA2%' and deleted = 0
           order by `name` limit 16)
  ) as top_rows
order by `name` limit 16
  • 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-22T21:08:45+00:00Added an answer on May 22, 2026 at 9:08 pm

    The first version has another set of temporary tables, which is useless and a waste of resources in this specific case.
    All the following will produce same result:

    SELECT * FROM T1;
    
    SELECT * FROM (SELECT * FROM T1);
    
    
    SELECT * FROM (SELECT * FROM (SELECT * FROM T1));
    
    ...
    ...
    

    to infinity 🙂

    And in your very specific case this will be enough:

    select *
               from phppos_items
               where 
                     (name like 'AB10LA2%' OR item_number like 'AB10LA2%' OR category like 'AB10LA2%')
               and deleted = 0
               order by `name` limit 16
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any performance difference between the two following queries: SELECT foo,bar FROM table
Other than readability, what is the difference between the following linq queries and when
Which are the diferrences between the following two queries? Both returns different rows: with
Is there any difference between following two ways of creating an object. Student s1
Question 1 Can anyone tell me if there is any difference between following 2
What is the difference between the following class methods? Is it that one is
What's the difference between the following two pieces of HTML (apologies if there are
What is the difference between the following statements? Statement 1: var=2**2*3 Statement 2: var2=2*2*3
What is the difference between the following maps I create (in another question, people
What is the difference between the following two snippets of code: using (Object o

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.