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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:42:26+00:00 2026-05-24T17:42:26+00:00

I am trying to join two tables in sql and get the count of

  • 0

I am trying to join two tables in sql and get the count of the second table. The second table has several columns, three of which together serve as the primary key. My query started as:

SELECT times.*, COUNT(paylog.*) AS `total` 
FROM times 
LEFT JOIN paylog 
ON paylog.type = 'work' 
AND paylog.targetID = times.id 

I get dinged for using the table name in the count() arguments:

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘*) AS total
FROM times
LEFT JOIN paylog ‘ at line 1

If there was a single unique column in the paylog table, I could follow the advice given here: Can I count number of rows in joined table? But that is not the case. How can I select the count of all the joined rows on the paylog table? I need to have it be a join because it currently gets the count with a subquery and it makes it a little slow.

  • 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-24T17:42:27+00:00Added an answer on May 24, 2026 at 5:42 pm

    Count will only return the number of non null values in a column or the number of rows in a result set for the special case of count(*). In other words count(paylog.*) isn’t valid SQL.

    You don’t need a unique column in the paylog table to do a valid count, any column will do. If the join is successful it’ll increment the count, if not the column’s value will be null and the count stays the same.

    If you’re trying to get the count of linked rows in paylog for each row in times then you’ll also need a group by times.id clause.

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

Sidebar

Related Questions

I'm trying to join two SQL tables, parent (which I have complete design control
I have a MySQL Left Join problem. I have three tables which I'm trying
I am trying to join together several audio files into one mp4/m4a file containing
I'm trying to use a join on three tables query I found in another
I am trying to write a SQL query where I am joining two tables
I've been trying to perform a join on two tables in MySQL, and the
Using extension syntax I'm trying to create a left-join using LINQ on two lists
I'm trying to get SQL Server to order by a column from a nested
really struggling to resolve this issue. using nhibernate Im trying to join two different
I'm new to EJB and trying to get my head around translating SQL concepts

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.