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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:32:25+00:00 2026-06-08T08:32:25+00:00

I have two tables viz. Total_Data and Distinct_S1 . Total_Data has 3.5 million rows.

  • 0

I have two tables viz. Total_Data and Distinct_S1.

Total_Data has 3.5 million rows. Fields: “S1”, “S2”, “S3”, “S4”

Distinct_S1 has 1 million rows. Fields: “S1”, “frequency”.
“S1” of Distinct_S1 consists of all distinct values which occur in “S1” of Total_Data.

Task at hand:
“frequency” of Distinct_S1 for S1 = ‘xxyy’ (suppose) should consist of the number of times ‘xxyy’ occurs in Total_Data.

I used the following query from within a python script(MySQLdb imported) to accomplish the Task at hand:

cur.execute("update Distinct_S1 set frequency=(select count(*) from Total_Data where S1='%s') where S1='%s'"%(S1_val, S1_val)

The above query works fine but it seems to take a lot of time. Is there any other faster way to achieve the same?

  • 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-08T08:32:28+00:00Added an answer on June 8, 2026 at 8:32 am

    You can use the multi-table update syntax with a join to update all rows at once. See the manual for the syntax.

    But a much easier way is to also insert all the values in the table directly without first populating it with the distinct values.

    INSERT INTO Distinct_S1 (S1, frequency)
    SELECT S1, COUNT(*)
    FROM Total_Data
    GROUP BY S1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables that are all the same, except one has a timestamp
I have two tables Visits and Labs Visit has these fields: id , patientID
I have two tables in my MySQL database, one is a library of all
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions
I have two tables: jobs & activities. A job consists of zero or more
I have two tables: A, B. I need to select all data from B.
I have two tables and want to compare rows on sqlite like this table1
I have two tables, I want to transfer all data from the first table
I have two tables Order , OrderStatus . Order has OrderId (pk), OrderStatusId (fk)

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.