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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:12:44+00:00 2026-06-07T15:12:44+00:00

I have 2 tables stores and shares in a mysql database. I am trying

  • 0

I have 2 tables stores and shares in a mysql database. I am trying to avoid an IN clause. Please see below for more details

select id, user_id from stores where user_id =7;
+----+---------+
| id | user_id |
+----+---------+
| 36 |       7 |
| 37 |       7 |


select stores_id,share_id from shares where share_id=7;
+-----------+----------+
| stores_id | share_id |
+-----------+----------+
|        15 |        7 |
|        38 |        7 |

Now I run this

SELECT stores.id
FROM   stores
WHERE  user_id = 7
UNION
(SELECT stores.id
 FROM   stores
 WHERE  id IN (SELECT stores_id
               FROM   shares
               WHERE  share_id = 7)); 

To get the below result:

+----+
| id |
+----+
| 36 |
| 37 |
| 15 |
| 38 |
+----+

QUESTION
How can I rewrite the query so that I don’t use the IN key word.?

  • 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-07T15:12:47+00:00Added an answer on June 7, 2026 at 3:12 pm

    This can help to you:

    select stores.id from stores where user_id = 7  
    UNION  
    select s1.id from stores s1 
           inner join shares s2 
           on s2.share_id = 7 
           and s1.id = s2.stores_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my mysql and php code layout: I have 3 tables tableA stores
I have a MySql database with three tables I need to combine in a
I have 2 tables, one of them stores items and the other one stores
I have a SQL Server 2008 database with 2 tables. These tables are Address
I have a MySQL database table that has a VARCHAR field storing a date
Background: I have one Access database (.mdb) file, with half a dozen tables in
So I have this application in ASP MVC 3. My database has two tables:
Image that I have a huge database which stores threads and posts from different
See the tables : http://dl.dropbox.com/u/10356431/Shared/screen.png Please help me to construct a SQL to find
I have a table that stores data that has been entered regarding the amount

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.