SQL

Hello. I got a problem that i cant get the hang of. I should print out the Publishers that published books written by at least the authors registered by the Publisher . How would I do that?

Attached: aaa.png (314x239, 12K)

Other urls found in this thread:

i.imgur.com/wRHXXcz.png
twitter.com/AnonBabble

joins

SELECT carti.Editura, carti.Titlu, autori.NumeAutor
FROM tema2bd.carti INNER JOIN tema2bd.carti_autori
ON carti.ISBN = carti_autori.ISBN
INNER JOIN tema2bd.autori
ON carti_autori.CodAutor = autori.CodAutor

This is what i got so far... I dont really know how i should proceed next with the WHERE, or what else is needed

do your own homework

SELECT books.Publisher, books.Title
FROM tema2bd.books INNER JOIN tema2bd.books_authors
ON books.ISBN = books_authors.ISBN
INNER JOIN tema2bd.authors
ON books_authors.AuthorCode = authors.AuthorCode

^ forgot to translate it.

Im trying :(

At the very least write it in proper english

could you correct me, please? I mean, please, really do.

Should have attended the class.

Attached: sql.webm (576x720, 834K)

> I should print out the Publishers that published books written by at least the authors registered by the Publisher .

Do you mean print print publishers who have published a book?

i know it does sound very ambiguous, but that's how the query translates and sounds. I hardly even understand what im supposed to do.
Essentially, I should print out the publishers of the books that were written by at least the authors registered by a particular other Publisher. That's what it asks of me at least.

i'd insert into her table, if you know what i mean

I've had and have the worst teachers on Databases and programming so far. I'm studying IT and economics though.
Had young, future Ph.D fags, that tried to teach us C# and now SQL... I've learnt more from google, stackoverflow, udemy and so on.

still... I have no idea how im supposed to do this query.

I have issues with SQL so I feel your pain, no schooling just self taught. When I get onto my computer I'll answer this for you as long as the thread is still alive. I can't see the image on mobile, and need to test it out locally to make sure it's working. It'll be a few hours.

Thank you kindly. I just hope it wont die like my hopes and dreams :)

How many tables, just two? Like I said I can't see your image.

There are 3 tables.
u could try this link if helps i.imgur.com/wRHXXcz.png

Err schema's, two schemas you're trying to grab from in one query? I.e. grab info from schema1.table where schema2.table as a join statement?

Select `database1.table1` from `database2` join `database1` on `database.table2` = `database2.table1` where `database2.table2` = ?

That should allow two databases to join using two tables from each, that's working query from my code, I just renamed the database and tables to generic names. If you can't figure it out with that code, when I get access to my desktop I'll make your databases and tables locally and make the query specifically for how you have it named and setup.

What the fuck that can't be real

> Print out the Publishers that published books written by at least the authors registered by the Publisher .

Just making sense of the question. So you want the other publishers, who published books by the author of said publisher's books.

SELECT DISTINCT b.PublisherName
FROM BOOKS AS b
WHERE b.ISBN IN (
SELECT ba1.ISBN
FROM BOOKS_AUTHORS as ba1
JOINS BOOKS AS b1 ON ba1.ISBN = b1.ISBN
WHERE b1.PublisherName = [publisher_name]
)


I didn't test this.

Oh 3, okay I see that image, unsure if my code above will work for that off the top of my head, but worth a shot making it work.. I'll make this locally and try to help you out, like I said it'll be a few hours until I can get off mobile and test it. Good luck in the mean time.

mhm, didn't the code just do an JOIN, but only with 2 tables, like i did above?
I still hardly understand what im supposed to do. The whole query sentence sounds awfully retarded to me. I translated it the best I could.

But you're doing an inner join, which is different than regular join, or join left or join right. I'll be back in few hours, see if answered it. Good luck.

This only shows the Publisher names, 2 of them specifically.


SELECT books.Publisher, books.Title
FROM tema2bd.books INNER JOIN tema2bd.books_authors
ON books.ISBN = books_authors.ISBN
INNER JOIN tema2bd.authors
ON books_authors.AuthorCode = authors.AuthorCode
WHERE books.PublisherName = 'nameOfPublisher';

What i wrote shows, 3 entries. Still, that's not what it is supposed to do. I think it should print out Publishers that ... published books of authors that already had books published by some other Publisher.

It looks like that's what should be doing.

Your query just shows the books of a given publisher though, right? And why would you need the `AUTHORS` table?

Because it should show the publishers of authors that had their books published by a particular other Publisher.
eg. If "John Marcels" had his book "Withering wallflower" published by "Exurb1a", some other book "SQL basics" by "abcd".
"Lennon Michael" with book "Book xyz" published by "Exurbia", some other book "Coca-Cola is a lie" by "qwer".
I need to make it so that it shows the names of those 2 publishers, the name of the authors and their books i guess.
So it should show
"abcd" - "John Marcels" - "SQL Basics"
"qwer" - "Lennon Michael" - "Coca-Cola is a lie"

load it in python and do a for loop

You don't really need the author name, it asks for publishers only. Since you have the AuthorCode there's no real need to match it with the AUTHOR table to fetch the name. Unless you want their names, or unless you want to verify the AuthorCode actually exists in the AUTHORS table. In that case you can. Just extend the outer query of then.

The only problem is i dont know how to do that at the moment