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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:48:00+00:00 2026-05-16T01:48:00+00:00

I have a table Books, where I store Book data (ISBN’s, Titles, Authors, etc.).

  • 0

I have a table Books, where I store Book data (ISBN’s, Titles, Authors, etc.). To tell which books are editions of each other I have a field Edition_Group_ISBN, which is an arbitrary ISBN from the group.

I’m having trouble getting this query, which is supposed to give the Book data and the number of other Editions based on the ISBN, to work:

   SELECT *, Editions_Count 
     FROM Books 
LEFT JOIN ((SELECT Edition_Group_ISBN, COUNT(*) AS Editions_Count 
              FROM Books 
             WHERE Edition_Group_ISBN IN (SELECT Edition_Group_ISBN 
                                            FROM Books)
             GROUP BY Edition_Group_ISBN) AS b 
       ) ON (Books.Edition_Group_ISBN = b.Edition_Group_ISBN 
           AND Books.Edition_Group_ISBN != NULL) 
    WHERE ISBN = 9780140447897

The query gives the book data for 9780140447897, but it gives the Editions_Count AS NULL, indicating that the LEFT JOIN isn’t working.

  • 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-16T01:48:01+00:00Added an answer on May 16, 2026 at 1:48 am

    Try this much simpler query:

    SELECT b.*, COUNT(*) AS Editions_count
    FROM Books b JOIN Books g USING (Edition_Group_ISBN)
    WHERE b.ISBN = 9780140447897
    GROUP BY b.book_id;
    

    I think you were making the problem much harder than you needed to. Your original query is full of confusing subqueries, at least one of which is totally superfluous.


    Re your comments:

    Yes, it works fine to compare ISBN to multiple values this way:

    SELECT b.*, COUNT(*) AS Editions_count
    FROM Books b JOIN Books g USING (Edition_Group_ISBN)
    WHERE b.ISBN IN (9780140447897, 9781934356555)
    GROUP BY b.book_id;
    

    COUNT(*) supports only a plain wildcard * which means count all rows in the group.

    Or you can use a specific expression like COUNT(g.Edition_Group_ISBN) which means count all rows in the group where that expression is non-null.

    But you can’t use g.* because it’s ambiguous. Does it count all rows in the group? (if so, just use COUNT(*)) Does it count non-null rows in the group? What would that mean anyway — count rows where all columns from g are non-null, or where any columns from g are non-null? For these reasons, COUNT(g.*) is simply not a legal construction in the SQL language.

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

Sidebar

Related Questions

I have a table Items which stores fetched book data from Amazon. This Amazon
So here's my situation. I have a books table and authors table. An author
I have a tableView that present a list of Books, each of the table
I have a table Classes, which stores data on different college classes (a unique
I have a book database(2 books in total right now) where for each book
I have several million records in a table (book/media data) and I would like
Let's say I have 10 books, each book has assigned some categories (ex. :php,
For example, if we have a table Books, how would we count total number
I work with PHP. I have a table named books. In table books I
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field

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.