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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:20:13+00:00 2026-05-31T09:20:13+00:00

I am using the publishers database and I am doing a query to list

  • 0

I am using the publishers database and I am doing a query to list the name and number of books sold at any bookstore for every author who sold any books at the Bookbeat store.

When I do this query

SELECT DISTINCT au_lname, au_fname, qty
from authors
JOIN titleauthor on titleauthor.au_id = authors.au_id
JOIN titles on titles.title_id = titleauthor.title_id
JOIN sales on sales.title_id = titles.title_id
JOIN stores on stores.stor_id = sales.stor_id
--WHERE stor_name LIKE 'Bookbeat' 

I get this result

Bennet  Abraham 5
Bennet  Abraham 10
Blotchet-Halls  Reginald    20
Carson  Cheryl  30
DeFrance    Michel  15
DeFrance    Michel  25
del Castillo    Innes   10
Dull    Ann 50
Green   Marjorie    5
Green   Marjorie    10
Green   Marjorie    35
Gringlesby  Burt    20
Hunter  Sheryl  50
Karsen  Livia   20
Locksley    Charlene    25
MacFeather  Stearns 20
MacFeather  Stearns 25
O'Leary Michael 20
O'Leary Michael 25
Panteley    Sylvia  40
Ringer  Albert  3
Ringer  Albert  10
Ringer  Albert  20
Ringer  Albert  25
Ringer  Albert  75
Ringer  Anne    3
Ringer  Anne    10
Ringer  Anne    15
Ringer  Anne    20
Ringer  Anne    25
Ringer  Anne    75
Straight    Dean    15
White   Johnson 15
Yokomoto    Akiko   20

But when i uncomment out the where I get this

Bennet  Abraham 10
Carson  Cheryl  30
DeFrance    Michel  15
Green   Marjorie    10
MacFeather  Stearns 25
O'Leary Michael 25
Ringer  Anne    15

I think what I am looking for is to sum the duplicates up so that I get the right answer.
So Bennet Abraham’s actual quantity would be 15.

  • 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-31T09:20:14+00:00Added an answer on May 31, 2026 at 9:20 am

    Here’s one way (you should always include the PK in the GROUP BY as author names aren’t guaranteed unique)

    SELECT au_lname, 
           au_fname, 
           SUM(qty) AS qty 
    FROM   authors 
           JOIN titleauthor 
             ON titleauthor.au_id = authors.au_id 
           JOIN titles 
             ON titles.title_id = titleauthor.title_id 
           JOIN sales 
             ON sales.title_id = titles.title_id 
           JOIN stores 
             ON stores.stor_id = sales.stor_id 
    GROUP  BY  authors.au_id,
               au_lname, 
               au_fname 
    HAVING MAX(CASE 
                 WHEN stor_name = 'Bookbeat' THEN 1 
               END) = 1 
    

    Or another that avoids summing authors that don’t qualify but does the Joins twice.

    ;WITH CTE As
    (
    SELECT     authors.au_id,
               au_lname, 
               au_fname,
               stor_name,
               qty          
    FROM   authors 
           JOIN titleauthor 
             ON titleauthor.au_id = authors.au_id 
           JOIN titles 
             ON titles.title_id = titleauthor.title_id 
           JOIN sales 
             ON sales.title_id = titles.title_id 
           JOIN stores 
             ON stores.stor_id = sales.stor_id 
    )
    SELECT au_lname, 
           au_fname, 
           SUM(qty) AS qty 
    FROM   CTE 
    WHERE au_id IN (SELECT au_id FROM CTE WHERE stor_name = 'Bookbeat')
    GROUP  BY  au_id,
               au_lname, 
               au_fname 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a database with three tables: Books (with book details, PK is CopyID),
I am using solr to make search on my database, and am trying to
I'm trying to parse Bibtex files using lex/yacc. Strings in the bibtex database can
I'm using a plugin to add tags to the contents of my database, and
I have a database where i am displaying books. Main page displays 2 links
I'm trying to insert data into the SQLite database using get EditText, but I
I'm working on a form using wxPython where I want want listctrl's list of
Our company publishes our software product's documentation using a custom-built content management system using
I have a web site with an API which publishes the information using JSON.
I have a setup where I'm serving simple python pages using the mod_python publisher.

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.