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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:07:28+00:00 2026-06-12T08:07:28+00:00

I have a MySQL table with a large amount of records (~20k), which is

  • 0

I have a MySQL table with a large amount of records (~20k), which is in 1NF. Unfortunately converting it to 2NF and above is not an option here.

The Table contains data such as

ClientName1 | ClientLastName1 | ClientZip1 | ... | Product1
ClientName1 | ClientLastName1 | ClientZip1 | ... | Product2
ClientName1 | ClientLastName1 | ClientZip1 | ... | Product3
ClientName2 | ClientLastName2 | ClientZip2 | ... | ProductX
ClientName3 | ClientLastName3 | ClientZip3 | ... | Product1
ClientName3 | ClientLastName3 | ClientZip3 | ... | Product2
ClientName4 | ClientLastName4 | ClientZip4 | ... | Product2
ClientName4 | ClientLastName4 | ClientZip4 | ... | Product3

What i would like to do is to get all the products of a client who has at least Product1.
So in the example above that would be the following records:

ClientName1 | ClientLastName1 | ClientZip1 | ... | Product1
ClientName1 | ClientLastName1 | ClientZip1 | ... | Product2
ClientName1 | ClientLastName1 | ClientZip1 | ... | Product3
ClientName3 | ClientLastName3 | ClientZip3 | ... | Product1
ClientName3 | ClientLastName3 | ClientZip3 | ... | Product2

For now lets assume (ClientName,ClientLastname) are unique for each client.
I used the following query assuming the the Table Name is clients

SELECT 
  ClientID
FROM
 clients cl 
WHERE (ClientName,ClientLastname) 
  IN ( 
    SELECT ClientName, ClientLastname
    FROM clients 
    GROUP BY ClientName,ClientLastname,Product 
    HAVING Product IN (Product1ID)
)

First of all this query runs for ages, and seems not to terminate (or at least not in a reasonable time) and second of all i think it is not correct.

  • 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-12T08:07:29+00:00Added an answer on June 12, 2026 at 8:07 am

    In an ideal world, my suggestion would be to try to normalize this table, as much as possible. As you can see, you have a mess of a table to try to work with.

    But have you tried something like this (See SQL Fiddle with Demo):

    select c.ClientName, 
      c.ClientLastName,
      c.ClientZip,
      c.Product
    from clients c
    inner join 
    (
      select ClientName
      from clients
      where Product = 'Product1' 
    ) x
      on c.ClientName= x.ClientName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a large mysql database table in which one column contains values ranging
I have a very large table in MySQL. I'm using a CHAR(32) field which
I have a table in MySQL with a large amount of data that I
I have a large MySQL table which looks like this: job_number time_on time_off 111
I have a MySQL database with a fairly large table where the products are.
I have two large tables in MySQL, one containing about 6,00,000 records and another
Let's say I have a very large MySQL table with a timestamp field. So
I have to dump large amount of data from file to a table PostgreSQL.
I have a large mysql table that I think might be using the wrong
I have a large MySql table with over 11 million rows. This is just

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.