473,395 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I really need help with this subquery

Hey I am really bad at databases and I am having problems writing this query.

I have to write a subquery that lists the authors( au_id, fname and lname) and the title_Id for their books for authors that have books published by the publisher with the greatest sales. I have no idea how to do about doing this. I am horrible at sql queries. Please help. This is all I have :/

Expand|Select|Wrap|Line Numbers
  1. select authors.au_id,fname,lname,author_titles.title_id
  2.    from authors left join author_titles on authors.au_id=author_titles.au_id
please help me. Thanks a lot!
Feb 23 '12 #1
3 1723
Rabbit
12,516 Expert Mod 8TB
After joining the author to the book, you just need to filter for the publisher with the most sales. That's where the subquery will come in, you just need a subquery to return the publisher id with the most sales.
Feb 23 '12 #2
Hey, thanks for the reply. I am still having problems with this. I am pretty bad when it comes to database. This is what I have now; Not really sure if I am on the right track but it returns 54 rows.. so I know it's incorrect.

Expand|Select|Wrap|Line Numbers
  1. SELECT authors.au_id,authors.fname,authors.lname,titles.title_id
  2.    FROM authors left join author_titles ON authors.au_id = author_titles.au_id,titles
  3.      WHERE pub_id IN(
  4.      SELECT pub_id FROM titles
  5.      WHERE sales=(SELECT MAX(sales)FROM titles));
Thanks for the help
*Mook*
Feb 24 '12 #3
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

The reason it's wrong is because you brought in a third table in your from clause without joining it.
Feb 24 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Naresh | last post by:
I have been having a problem and I don't know where to go for help. The microsoft support is only for a fees. Can anyone at all please at least point to a site or some place where I can hope for some...
9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
4
by: _link98 | last post by:
Which of the UDB 8.2.2 ESE unix executables really need to gain root privilege while they are running? In my installation, the db2sysc file is owned by the instance-owner (and relevant admin...
1
by: Paul Mendez | last post by:
I really need your assistance. I tried what you gave me and it did not work and I am thinking that the formatting that showed up when u saw my posting might have confused you. So I made sure to...
1
by: John Smith | last post by:
I have a two dimentional char array. Before filling it using strtok(), I reset its elements to '\0' using two nested for loops. The code works as I hope it would but I wonder whether I really need...
3
by: Chris | last post by:
Wait.. before you flame.. If someone can program in Java, or Javascript, or C, or (insert your language here that uses basically the same syntax as C#), and that person knew how to program in...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
7
by: gaidar | last post by:
Hi, everybody, I'm just wondering if someone really need stuff like this: http://msdn2.microsoft.com/library/ms123401.aspx. If you answer yes than explain, please. Thanks! Gaidar
1
lolixpop
by: lolixpop | last post by:
Hi everybody thanks for reading! i have a few actionscript questions that i really need help on...any help would be greatly appreciated! Okay so i came upon this tutorial:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.