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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:50:26+00:00 2026-06-03T18:50:26+00:00

I have the following SQL: SELECT `table1`.`value`, `table2`.* FROM `table2` INNER JOIN `table1` ON

  • 0

I have the following SQL:

SELECT `table1`.`value`, `table2`.* 
FROM `table2` 
INNER JOIN `table1` ON `table2`.`product_id` = `table1`.`entity_id`
WHERE `table2`.`created_at` > '2012-04-23' and 
(`table1`.`value` = 264 OR `table1`.`value` = 260)
order by order_id

Which returns a result set like this (This is only a part of the returned results):

value  order_id   ...
260    1234
260    1235
260    1236
264    1236
260    1237
260    1238
260    1239
264    1239
264    1240
260    1241

What I want is a query that will take these results and only return orders where the order_id contains both value 260 and 264. Based on this example, the end result I am looking for is

260   1236
264   1236
260   1239
264   1239

My thought is this can be done with a subset but I am not exactly sure on the details to accomplish 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-03T18:50:29+00:00Added an answer on June 3, 2026 at 6:50 pm

    This can be accomplished with relational division:

    select r.order_id from (
      select 
        dividend.*  
      from your_table_or_query as dividend  -- assumes no duplicates in `dividend`; use `distinct` if there are any
      inner join divisor
      on dividend.value = divisor.value
    ) as r
    group by r.order_id
    having count(*) = (select count(*) from divisor);
    

    result:

    +----------+
    | order_id |
    +----------+
    |     1236 |
    |     1239 |
    +----------+
    2 rows in set (0.00 sec)
    

    where your query is your_table_or_query and

    select 260 as value from dual union select 264 as value from dual
    

    is divisor.

    This will return the order ids 1236 and 1239; they can then be joined to original query to get all the rows with those order ids if that’s what you want.


    Full query along with insert statements:

    create table divisor (value int);
    insert into divisor values (260), (264);
    
    create table your_table_or_query (value int, order_id int);
    insert into your_table_or_query values (260, 1234), (260, 1235), (260, 1236), (264, 1236), (260, 1237), (260, 1238), (260, 1239), (264, 1239), (264, 1240), (260, 1241);
    
    
    select y.* from (
      select r.order_id from (
        select
          dividend.*
        from your_table_or_query as dividend
        inner join divisor
          on dividend.value = divisor.value
      ) as r 
      group by r.order_id
      having count(*) = (select count(*) from divisor)
    ) as quotient
    inner join your_table_or_query y
      on quotient.order_id = y.order_id;
    

    Result:

    +-------+----------+
    | value | order_id |
    +-------+----------+
    |   260 |     1236 |
    |   264 |     1236 |
    |   260 |     1239 |
    |   264 |     1239 |
    +-------+----------+
    4 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sql statement: SELECT COUNT(table2.programName), table2.programName FROM table1 LEFT JOIN table2
I have the following SQL: SELECT * FROM [Database].dbo.[TagsPerItem] INNER JOIN [Database].dbo.[Tag] ON [Tag].Id
I have the following sql query: UPDATE (SELECT * FROM table_A INNER JOIN table_B
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
So I have the following group by SQL select count(*) as NO_OF_MSGS,FROM_USER,PROFILE_IMG,MSG from MESSAGES
I have the following query: select id from table1 where some_func(?) = 1; where
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have the following SQL statement: Select Choose(1,Orders.Employee, Orders.Customer) as Name1, Choose(2,Orders.Employee, Orders.Customer) as
I have the following SQL statement SELECT c.CorpSystemID, c.SystemName , case when a.TaskItemID is
Let's say I have the following SQL query SELECT id, name, title, description, time

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.