December 28, 2023 at 2:48 pm
Couldy You help me with this task, please?
You are working with the library books database.
The Books table has the columns id, name, year.
The library has new books whose information is stored in another table called "New", however they do not have a year column.
Write a query to select the books from both tables, Books and New, combining their data. For the year column of the New books use the value 2022.
Also, select only the books that are released after the year 1900.
The result set should contain the name and year columns only, ordered by the name column alphabetically.
My solution:
SELECT name, (2002 AS year)
FROM New
UNION
SELECT name, year
FROM Books
WHERE year > 1900
ORDER BY name ASC
I do really not know how to correct it to be done in a properway
December 28, 2023 at 6:20 pm
You can't generally define aliases INSIDE expressions.
Drew
PS: You're dates don't match.
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
December 28, 2023 at 9:45 pm
Did the query you wrote produce the correct results? What was wrong with it?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
December 29, 2023 at 9:49 am
I do not know how to change column name from "yeatr" to proper item. Everything is OK apart from this column name.
January 5, 2024 at 10:52 am
If you drop the brackets around (2002 AS year), it would work. Alternatively, you could SELECT from the Books table first and then the SELECT against New would inherit the column names.
April 9, 2024 at 10:19 am
This was removed by the editor as SPAM
April 30, 2024 at 7:17 am
This was removed by the editor as SPAM
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply