SQL query (MS Access) - TechRepublic
Question
March 19, 2008 at 05:18 PM
benmidgley

SQL query (MS Access)

by benmidgley . Updated 18 years, 2 months ago

Hi,

I am trying to learn how to use SQL and am completely stuck atm. Any help at all would be most welcomely received. I have stared at this for so long that it isn’t even funny any more 🙂 [Apologies for being a total noob].

I have created a database which represents an online bookstore. I would like to complete the following two queries.

1. Output a list of bookgenres in order of popularity.

I have attempted it as follows but with no love .

SELECT CAT.Genre_code, GEN.Description, COUNT (CUSTORDPROD.ISBN) AS Rank
FROM GEN, CAT, CUSTORDPROD
WHERE GEN.Genre_code = CAT.Genre_code
AND CAT.ISBN = CUSTORDPROD.ISBN
GROUP BY CUSTORDPROD.ISBN, GEN.Genre_code
ORDER BY GEN.Genre_code DESC;

2. List everyone who has bought two or more books by the same author.

SELECT CUST.Customer_name, CUSORDS.Order.ID, AUTH.Author_ID, AUTH.First_Name, AUTH.Last_name
FROM CUST, CUSORDS, CUSTORDPROD, BOOKAUTH, AUTH
WHERE CUST.Customer_ID = CUSORDS.Customer_ID
AND CUSORDS.Order_ID = CUSTORDPROD.Order_ID
AND CUSTORDPROD.ISBN = BOOKAUTH.ISBN
AND BOOKAUTH.Author_ID = AUTH.Author_ID
AND AUTH.Author_ID =
(SELECT CUSORDS.Order_ID
AND CUSTORDPROD.ISBN
AND AUTH.Author_ID
FROM CUST, CUSTORDPROD, AUTH
WHERE Author_ID >2);

The frustrating thing is knowing that there is something very simple that I’m just failing to grasp. Argh!

Thanks in advance for any help!

This discussion is locked

All Comments