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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:49:58+00:00 2026-06-19T03:49:58+00:00

My table – pid id subject section 1 1 7 0 2 1 12

  • 0

My table –

pid     id  subject section
1        1  7            0
2        1  12           0
3        1  13           1
4        1  13           2
5        1  13           3
6        1  14           3
7        1  14           4
8        2  15           1
9        2  16           1

Result to be obtained –

id subject total
1    7      1
1    12     1
1    13     3
1    14     2

My Query –

SELECT DISTINCT(SUBJECT), count(section)
FROM mytable
GROUP BY section
WHERE id = 1

But this is throwing an error, let me know what I am doing wrong

Error

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 'WHERE id = 1' at line 4: SELECT DISTINCT(SUBJECT), count(section) FROM mytable GROUP BY section WHERE id = 1 
  • 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-19T03:49:59+00:00Added an answer on June 19, 2026 at 3:49 am

    The syntax error is due to a misplaced WHERE clause. It needs to go before GROUP BY. Additionally:

    • You are grouping by the column you want to sum.
    • You are using DISTINCT unnecessarily.

    Query should be on this line:

    SELECT SUBJECT, count(section)
    FROM mytable
    WHERE id = 1
    GROUP BY SUBJECT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table structure: country season points Current query: SELECT SUM(points) AS total, country FROM table
table: postid|userid|post|replyto post sql SELECT * FROM table WHERE postid=12 total replies sql SELECT
Table - T1 (id, Description) Table - T2 (id, fk_id,Dates, Amount) select d.Description,dt.Dates,dt.Amount from
table.rows.length in Java script returns the count of rows in the table including rows
Table 1: Student StudentID, StudentName Table 2: Course CourseID, CourseName Table 3: Group GroupID,
Table has surrogate primary key generated from sequence. Unfortunately, this sequence is used for
Table (ipvote) Table (pictures) What is the SQL query to retrieve all the images
Table: laterecords ----------- studentid - varchar latetime - datetime reason - varchar My Query:
Table view center cell always highlight like a picker. If I select the center
I have an Oracle 10g table containing 2 date columns, DATE_VALID_FROM from and DATE_VALID_TO.

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.