Mareh A. - #19
Mareh A.#19mareh-aboghanem wants to merge 1 commit into
Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
rafasilpereira
left a comment
There was a problem hiding this comment.
Good job!
Your implementations in task 2 were good and worked as expected!
I would review the queries for task 1 making sure that the results that you are getting is the expected.
|
|
||
| -- **Question 1** — List the title and published year of every book in the `'Science Fiction'` genre, ordered by published year (oldest first). | ||
| SELECT title , published_year FROM books | ||
| WHERE books.genre = 'Science Fiction'; |
There was a problem hiding this comment.
This is query is not ordering by published year with oldest first. How would you change it?
| -- **Question 3** — Show every book in the database along with its author's full name. Combine `first_name` and `last_name` into a single column called `author`. _(Hint: you will need a JOIN.)_ | ||
|
|
||
| SELECT title , published_year , authors.first_name || ' ' || authors.last_name AS author FROM books | ||
| JOIN authors ON author_id = books.author_id; |
There was a problem hiding this comment.
When I run this query, these are the results that are I receive below with duplicate results. The problem is in the JOIN and the id used for checking. How would you fix it?
Harry Potter and the Philosopher's Stone 1997 J.K. Rowling
Harry Potter and the Philosopher's Stone 1997 George R.R. Martin
Harry Potter and the Philosopher's Stone 1997 J.R.R. Tolkien
Harry Potter and the Philosopher's Stone 1997 Agatha Christie
Harry Potter and the Philosopher's Stone 1997 Stephen King
| -- **Question 4** — List all books written by Stephen King. Show the title and published year, ordered by year. _(Hint: JOIN the two tables and filter on the author's name.)_ | ||
|
|
||
| SELECT title , published_year FROM books | ||
| JOIN authors ON author_id = books.author_id |
There was a problem hiding this comment.
This query doesn't return results. The problem is with the choose of the id to compare
| -- **Question 6** — Add one book for the author you just inserted. It can be a real book or a made-up one. | ||
|
|
||
| INSERT INTO books(title,published_year,genre,author_id) | ||
| VALUES("HI",2026,"Horror",25); |
There was a problem hiding this comment.
Good! A challenge: there is a way of doing a SELECT to find the author_id. How would you do that? Tip: I can add doing something like ...VALUES('Rafael', 'Pereira', (SELECT id FROM customers)) ;)
| -- **Question 7** — The genre for "The Dark Tower: The Gunslinger" was entered incorrectly as `'Fantasy'`. It should be `'Horror'`. Write an UPDATE to fix it, then verify the change with a SELECT. | ||
| UPDATE books | ||
| SET genre = 'Horror' | ||
| WHERE title = "The Dark Tower: The Gunslinger"; |
There was a problem hiding this comment.
Good one here! Adding exactly the title for UPDATE or DELETE and avoiding using LIKE makes you changing one what is needed, without the risk of updating or deleting not wanted rows
|
|
||
| -- These cover topics slightly beyond the core material. Have a go if you finish early. | ||
|
|
||
| -- **Bonus A** — How many books are there per genre? Show the genre name and the count, ordered from most to fewest books. |
| // TODO: set learned = 1 for the card with the given id | ||
| // return the updated row, or null if not found | ||
| throw new Error('Not implemented'); | ||
| const stmt = db |
There was a problem hiding this comment.
The const stmt is not used in any other place and you are storing in memory. How would you run the UPDATE without creating a const?
| const stmt = db.prepare("SELECT * FROM decks"); | ||
| const rows = stmt.all(); | ||
| return rows; | ||
| //throw new Error('Not implemented'); |
There was a problem hiding this comment.
If you have the same comment many times, maybe better to remove them all? ;)
No description provided.