needing some serious help on a few SQL Issues, PLEASE ?! - HotUKDeals
We use cookie files to improve site functionality and personalisation. By continuing to use HUKD, you accept our cookie and privacy policy.
Get the HUKD app free at Google Play

Search Error

An error occurred when searching, please try again!

Login / Sign UpSubmit

needing some serious help on a few SQL Issues, PLEASE ?!

SAVE4IT Avatar
6y, 9m agoPosted 6 years, 9 months ago
Hi there, I am having difficulty doing a few queries in SQL. The first one being:

1. List the details for all visits associated with Ms Anne Logan.

I have built this, but its not working :(

SELECT Guest.FirstName, Guest.Surname, BookingDetails.HotelName, BookingDetails.dateofarrival, BookingDetails.dateofdeparture
FROM employee, BookingDetails
WHERE surname='Logan' AND firstname='Anne'
AND Guest.GuestID = BookingDetails.GuestID

Please help :( Sooo frustrating!
SAVE4IT Avatar
6y, 9m agoPosted 6 years, 9 months ago
Options

All Comments

(22) Jump to unreadPost a comment
Comments/page:
#1
sounds like some-ones homework.....
#2
WHERE depno surname='Logan' AND firstname='Anne')

Whats that bracket for?
#3
Whoops, its meant to have a bracket around the end of surname too

e.g

... (surname='Logan' AND firstname='Anne')
#4
what happens when you run the query?
#5
Should it be Guest.Surname?

Whats Depno?
#6
imafish2002
what happens when you run the query?


it doesnt run and says there is a problem with the syntax
#7
I think you have a few problems:

i. You're trying to bring back columns which you have not specified the table in your FROM statement (GUEST). Is your EMPLOYEE in the FROM clause should be GUEST?
ii. What is DeptNo in your WHERE clause? Are you missing a condition?
#8
OK, I see you've tidied the original post up, the problem you have is as stated in my point i. you are trying to bring back columns from the GUEST table while you have not specified it in the FROM clause.
#9
Title should read: "Need someone to do my SQL assignment for me - PLEASE?!" :roll:

btw, could an error be caused by the things highlighted in bold not matching up (i.e. referring to FirstName and then firstname later on)
SELECT Guest.FirstName, Guest.Surname, BookingDetails.HotelName, BookingDetails.dateofarrival, BookingDetails.dateofdeparture
FROM employee, BookingDetails
WHERE surname='Logan' AND firstname='Anne'
AND Guest.GuestID = BookingDetails.GuestID
#10
My consultantation invoice has been sent :P.
banned#11
SELECT A.FirstName, A.Surname, B.HotelName, B.dateofarrival, B.dateofdeparture
FROM Guest A, BookingDetails B
WHERE A.surname='Logan' AND A.firstname='Anne'
AND A.GuestID = B.GuestID
#12
csiman
SELECT A.FirstName, A.Surname, B.HotelName, B.dateofarrival, B.dateofdeparture
FROM Guest A, BookingDetails B
WHERE A.surname='Logan' AND A.firstname='Anne'
AND A.GuestID = B.GuestID


Thanks!
banned#13
SAVE4IT;7928707
Thanks!

Does it work now? :thinking:
#14
csiman
Does it work now? :thinking:


yeah, not totally sure why? Think it was a bit scrappy that was about it
banned#15
SAVE4IT;7928761
yeah, not totally sure why? Think it was a bit scrappy that was about it

you had a database called 'employee' referencing fields from a database called Guest
#16
csiman;7928828
you had a database called 'employee' referencing fields from a database called Guest


No they didn't. They had tables incorrectly referenced. The database didn't form any part of the SQL statement.
#17
*Was going to help but has been beaten to it*

*Slunks off to work on XML*
#18
oldmanhouse;7928623
Title should read: "Need someone to do my SQL assignment for me - PLEASE?!" :roll:

btw, could an error be caused by the things highlighted in bold not matching up (i.e. referring to FirstName and then firstname later on)
SELECT Guest.FirstName, Guest.Surname, BookingDetails.HotelName, BookingDetails.dateofarrival, BookingDetails.dateofdeparture
FROM employee, BookingDetails
WHERE surname='Logan' AND firstname='Anne'
AND Guest.GuestID = BookingDetails.GuestID



If your database has the column names set to case sensitive, then you're off to a bad start. Column names should be set to case insensitive as having multiple columns with the same name but in different case is bad design practice. I assume that the OP is using SQL Server/Access as the main databases have this turned off by default.
banned#19
suchafunkymonkey;7928883
No they didn't. They had tables incorrectly referenced. The database didn't form any part of the SQL statement.

OK - I meant tables. Been out the game a while now after 20 years in lol.
Retired 4 years ago thanks to 10 years contracting :)
#20
SELECT AVG(DateofDeparture-Dateofarrival)
FROM BookingDetails

Would this find the average length of stay between the two dates?
#21
SAVE4IT;7929490
SELECT AVG(DateofDeparture-Dateofarrival)
FROM BookingDetails

Would this find the average length of stay between the two dates?


I think if you run it, you'll find out. Surely the point of these questions is that you should be learning SQL and not asking for the answers?
banned#22
suchafunkymonkey;7929550
I think if you run it, you'll find out. Surely the point of these questions is that you should be learning SQL and not asking for the answers?

well said! You cant learn without a bit of thought and trial and error. You wont learn anything by just asking for the answers on a forum.

Post a Comment

You don't need an account to leave a comment. Just enter your email address. We'll keep it private.

...OR log in with your social account

...OR comment using your social account

Thanks for your comment! Keep it up!
We just need to have a quick look and it will be live soon.
The community is happy to hear your opinion! Keep contributing!