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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:15:50+00:00 2026-06-12T11:15:50+00:00

Im trying to update a table with the counts of another table. I think

  • 0

Im trying to update a table with the counts of another table. I think I’ve got the structure of the query right but I keep getting a SQL error:

UPDATE c
SET c.sales = p.ProductCount
FROM products c
INNER JOIN
(SELECT p_key, COUNT(*) AS ProductCount 
FROM sales
GROUP BY p_key) p
ON c.link = p.p_key

The structure of the two tables:

Products
product_name (varchar),
sales (int),
link (char),

Sales
email (char),
p_key (char)

I’ve just shown the key columns. Any help appreciated.

  • 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-12T11:15:52+00:00Added an answer on June 12, 2026 at 11:15 am

    You are using the join syntax for T_SQL, in MySQL do this,

    UPDATE  products c
            INNER JOIN 
            (
                SELECT  p_key,
                        COUNT(*) AS ProductCount
                FROM sales
                GROUP BY p_key
            ) p
                ON c.link = p.p_key
    SET c.sales = p.ProductCount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to Update a table but I keep getting the exception : Update
I'm trying to update one table based on values in another table. What's wrong
Here is my trial query. I am trying to update TABLE1 table with it's
I am trying to create an update query and making little progress in getting
I'm trying to update a column in table Profiles with a COUNT from another
I'm trying to update a table based upon the user id from another table.
I'm trying to create a standard UPDATE query for a table. However, if certain
I'm trying to get php to update a MySQL table using UPDATE statement but
I am trying to update table A with data from table B. I thought
Im trying to update a table with the following code. If I change WHERE

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.