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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:45:47+00:00 2026-06-03T00:45:47+00:00

Inspired by this article I tried optimizing an export function of a memberlist from

  • 0

Inspired by this article I tried optimizing an export function of a memberlist from our database.

The original queries look like this:

-- First query
SELECT
    *
FROM
    members_customer_id_0000000169
WHERE
    deleted = '0000-00-00 00:00:00'

-- Second query run for every result from first query
SELECT
    stores.external_store_id AS local_store_id
FROM
    regions,
    stores,
    stores_reference_members_customer_id_0000000169
WHERE
    regions.customer_id = 169
AND
    stores.region_id = regions.id
AND
    stores_reference_members_customer_id_0000000169.member_id =' . $result['id'] . '
AND
    stores_reference_members_customer_id_0000000169.store_id = stores.id

The first query returns 180k rows and its performance is not efficient the second query fetch all 180k times.

I tried doing this instead:

SELECT
    members_customer_id_0000000169.*,
    stores.external_store_id AS local_store_id
FROM
    members_customer_id_0000000169
LEFT JOIN
    stores_reference_members_customer_id_0000000169
ON
    stores_reference_members_customer_id_0000000169.member_id = members_customer_id_0000000169.id
JOIN
    regions
JOIN
    stores
WHERE
    members_customer_id_0000000169.deleted = '0000-00-00 00:00:00'
AND
    regions.customer_id = 169
AND
    stores.region_id = regions.id
AND
    stores_reference_members_customer_id_0000000169.store_id = stores.id

The result is only 140k rows. The reason is probably that I don’t get members without a local_store_id as I intended.
And I’m unsure what the problem is.

I’m confident that I’m doing something wrong with the joins because of the many tables and WHERE clauses, but I only have experience with doing LEFT/RIGHT joins between two tables.

Can anyone identify the problem?

  • 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-03T00:45:49+00:00Added an answer on June 3, 2026 at 12:45 am

    Each JOIN operation should have a corresponding ON statement to tell SQL how to merge the records from the new table. It seems like you are doing some of that logic in the WHERE statement, which could be causing the issue.

    Also, as far as getting members without a local_store_id, it could be the fact that you are doing an inner join on stores, so your result set only has members that have a corresponding row in stores based on your join logic. A left outer join may give you what you’re looking for.

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

Sidebar

Related Questions

This question is inspired from Joel's Making Wrong Code Look Wrong http://www.joelonsoftware.com/articles/Wrong.html Sometimes you
My question is partially inspired by this article written by Eric Lippert: http://blogs.msdn.com/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe.aspx Using
Today I encountered this article about decimal expansion and I was instantaneously inspired to
This question is inspired by the article Why are Facebook, Digg, and Twitter so
This question is inspired by this question . I'd like to get a dictionary
This is inspired by/taken from this thread: http://www.allegro.cc/forums/thread/603383 The Problem Assume the user gives
Inspired by this article , I was playing around with the Ruby method calling
Inspired by this question on Meta , I wrote two queries on the Stack
Inspired by this question I decided to test the rank() function, trying to see
I've decided to look into Clojure (inspired by this book ). After a bit

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.