Question:
Help with SQL Select statement?
paulette
2014-03-19 01:59:28 UTC
I should write a SQL query that will select all of the books that are currently checked out and are past due to be returned, which have a value greater than $10.00 from a library system. I should return the name, address, postal code, and phone number of the borrower, the name and phone number of the librarian responsible for the transaction, the date the book was due to be returned, and the name, cost, and ISBN number of the book. And my query should be sorted the list by the return date in descending order.

This is what i wrote

Select a.returndate as booklended ,a.isbn_number as booklended, b. as borrower,
b.address as borrower, b.postalcode as borrower, b. phonenumber as
borrower, c.name as librarian, c.phonenumber as librarian
from booklended.a, librarian.c, borrower.b
where a. librarian id= c.librarianid
and a.librarycard = b.librarycard
and returndate < curdate()
and cost > 10.00
order by a. returndate desc;


However I am getting this error 5: invalid schema name: BOOKLENDED in statement [Select a.returndate as booklended ,a.isbn_number as booklended, b. as borrower, b.address as borrower, b.postalcode as borrower, b. phonenumber as borrower, c.name as librarian, c.phonenumber as librarian

from booklended.a]

Could I please get a guide on how I may correct this. Thank you
Three answers:
Mayn
2014-03-19 02:33:06 UTC
I'm no expert, but this whole SQL statement is a mess. You have quite a few mistakes which will not cause errors and quite a few which will.



1. Why use 'booklended' as column heading for returndate and isbn_number? The same goes for reusing borrower as column name. I think you don't know what "as XXXX" means after a column name. It means you are changing the column heading for appearance purpose.

2. Third column shows "b." That b. should be followed by a column name from the table represented by b (borrower).

3. Near the end you use column names without aliases. Fix that.

4. You cannot have a space after the . when using an alias and column names cannot include spaces.
?
2014-03-19 02:08:10 UTC
There shouldn't be a period between the table name and the table alias in the FROM clause. Change it to:



from booklended a, librarian c, borrower b
anonymous
2014-03-19 02:58:04 UTC
Dear, if you want to help in SQL Select statement. this tutorial may be helpful to you.

www.javatpoint.com/sql-tutorial


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...