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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:06:27+00:00 2026-05-15T02:06:27+00:00

SELECT * from `employees` a LEFT JOIN (SELECT phone1 p1, count(*) c, FROM `employees`

  • 0
SELECT * from `employees` a 
LEFT JOIN (SELECT phone1 p1, count(*) c, FROM `employees` GROUP BY phone1) b
ON a.phone1 = b.p1;

I’m not sure if it is this query in particular that has the problem. I have been getting terrible performance in general with this database. The table in question has 120,000 rows. I have tried this particular query remotely and locally with the MyISAM and InnoDB engines, with different types of joins, and with and without an index on phone1. I can get this to complete in about 4 minutes on a 10,000 row table successfully but performance drops exponentially with larger tables. Remotely it will lose connection to the server and locally it brings my system to its knees and seems to go on forever.

This query is only a smaller step I was trying to do when a larger query couldn’t complete. Maybe I should explain the whole scenario. I have one big flat ugly table that lists a bunch of people and their contact info and the info of the companies they work for. I’m trying to normalize the database and intelligently determine which phone numbers apply to individual people and which apply to an office location. My reasoning is that if a phone number occurs multiple times and the number of occurrence equals the number of times that the street address it is attached to occurs then it must be an office number. So the first step is to count each phone number grouping by phone number. Normally if you just use COUNT()…GROUP BY it will only list the first record it finds in that group so I figured I have to join the full table to the count table where the phone number matches. This does work but as I said I can’t successfully complete it on any table much larger than 10,000 rows. This seems pathetic and this doesn’t seem like a crazy query to do. Is there a better way to achieve what I want or do I have to break my large table into 12 pieces or is there something wrong with the table or db?

Edit, to answer Rob’s request:

1, 'PRIMARY', 'a', 'ALL', '', '', '', '', 60097, ''
1, 'PRIMARY', '', 'ALL', '', '', '', '', 9363, ''
2, 'DERIVED', 'employees1', 'ALL', '', '', '', '', 60097, 'Using temporary; Using filesort'
  • 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-15T02:06:28+00:00Added an answer on May 15, 2026 at 2:06 am

    If this is for a one-time normalization “cleanup”, I would push your subquery into a temporary table, index, do you join against it, and then drop it when you’re done.

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

Sidebar

Related Questions

I have a query that looks like this: SELECT * FROM employees e LEFT
I need a select from table which does not have column that tells when
$query = SELECT * FROM `table`; $results = mysql_query($query, $connection); If 'table' has no
Two snippets of MySQL: SELECT * FROM annoyingly_long_left_hand_table LEFT JOIN annoyingly_long_right_hand_table ON annoyingly_long_left_hand_table.id =
If I have a query like: Select EmployeeId From Employee Where EmployeeTypeId IN (1,2,3)
select * from myTable where myInt will not show any possible_keys when explaining the
This SELECT * FROM SOME_TABLE WHERE SOME_FIELD LIKE '%some_value%'; is slower than this SELECT
If I select from a table group by the month, day, year, it only
The following SQL SELECT * FROM customers converted to this in LINQ var customers
I'm not sure if an answer for this already exists, as I can't figure

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.