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

  • Home
  • SEARCH
  • 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 8735355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:02:05+00:00 2026-06-13T10:02:05+00:00

I have two tables that share the same column ( C ) but SQL

  • 0

I have two tables that share the same column (C) but SQL tells me I have an error

Here is the first table from the first query:

SELECT   E.C AS C, 
         COUNT(C) AS CC
FROM     E
GROUP BY E.C

And here is the second query:

SELECT   E.C AS C, 
         COUNT(C) AS Num
FROM     E, G
WHERE    E.G = G.L
         AND G.G <
                    (SELECT min(G.G) 
                     FROM   G
                     WHERE  G.L = "BLAH")

GROUP BY E.C

So I tried to simply put these two together by putting JOIN in between them. But this doesn’t join them, even though they share the same column C. It simply says I have a syntax error. What is wrong? And how do I fix it? I have confirmed that when run separately, they produce the correct output with a column C

Below is the total JOIN execution

(SELECT   E.C AS C, 
             COUNT(C) AS CC
    FROM     E
    GROUP BY E.C)

JOIN

(SELECT   E.C AS C, 
             COUNT(C) AS Num
    FROM     E, G
    WHERE    E.G = G.L
             AND G.G <
                        (SELECT min(G.G) 
                         FROM   G
                         WHERE  G.L = "BLAH")

    GROUP BY E.C)

And the error is
Error code 1064, SQL state 42000: 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 ‘JOIN

(SELECT   E.C AS C, 
         COUNT(C) AS Num' at line 6
Line 1, column 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-13T10:02:07+00:00Added an answer on June 13, 2026 at 10:02 am

    You did not show your syntax error but, I am guessing your has to do with the following line:

    COUNT(C) AS CC
    

    Since both tables have a column C, the query does not know which table to return the value from. You need to preface it with the table name or alias.

    This line works in your first query because you only had one column called C, once you have two you need to specify which one you want to return.

    Based on your edit, you are missing aliases for the subqueries and the on condition for the join:

    select t1.C, t1.cc, t2.num
    from 
    (
        SELECT   E.C AS C, 
                 COUNT(C) AS CC
        FROM     E
        GROUP BY E.C
    ) t1  -- added alias
    INNER JOIN
    (
        SELECT   E.C AS C, 
                 COUNT(E.C) AS Num  -- added table name, since column c exists in both tables
        FROM    E 
        JOIN    G
            ON E.G = G.L
        WHERE  G.G < (SELECT min(G.G) 
                       FROM   G
                       WHERE  G.L = "BLAH")
        GROUP BY E.C
    ) t2  -- added alias
        on t1.C = t2.C  -- added on clause
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, that share the same definition. I commonly insert new objects
I have two different databases that share some of the same tables, and differ
I have two tables that are related via a mapping table: keywords titles I
I have two tables with the exact same schema in SQL Server 2008 Standard
I have two Tables: Users and Permission. They share 2 columns with the same
I have several LINQ-to-Entities queries that hit the same two tables and have the
I have two table functions that return a single column each. One function is
I have two tables that link together through an id one is submit_moderate and
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,

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.