Groups

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

    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!

    22 Comments

    sounds like some-ones homework.....

    WHERE depno surname='Logan' AND firstname='Anne')

    Whats that bracket for?

    Original Poster

    Whoops, its meant to have a bracket around the end of surname too

    e.g

    ... (surname='Logan' AND firstname='Anne')

    what happens when you run the query?

    Should it be Guest.Surname?

    Whats Depno?

    Original Poster

    imafish2002;7928518

    what happens when you run the query?



    it doesnt run and says there is a problem with the syntax

    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?

    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.

    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

    My consultantation invoice has been sent :P.

    Banned

    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

    Original Poster

    csiman;7928671

    SELECT A.FirstName, A.Surname, B.HotelName, B.dateofarrival, … SELECT A.FirstName, A.Surname, B.HotelName, B.dateofarrival, B.dateofdepartureFROM Guest A, BookingDetails BWHERE A.surname='Logan' AND A.firstname='Anne'AND A.GuestID = B.GuestID



    Thanks!

    Banned

    SAVE4IT;7928707

    Thanks!


    Does it work now? :thinking:

    Original Poster

    csiman;7928718

    Does it work now? :thinking:



    yeah, not totally sure why? Think it was a bit scrappy that was about it

    Banned

    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

    csiman;7928828

    you had a database called 'employee' referencing fields from a database … 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.

    *Was going to help but has been beaten to it*

    *Slunks off to work on XML*

    oldmanhouse;7928623

    Title should read: "Need someone to do my SQL assignment for me - … 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.dateofdepartureFROM employee, BookingDetailsWHERE 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

    suchafunkymonkey;7928883

    No they didn't. They had tables incorrectly referenced. The database … 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

    Original Poster

    SELECT AVG(DateofDeparture-Dateofarrival)
    FROM BookingDetails

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

    SAVE4IT;7929490

    SELECT AVG(DateofDeparture-Dateofarrival)FROM BookingDetailsWould this … SELECT AVG(DateofDeparture-Dateofarrival)FROM BookingDetailsWould 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

    suchafunkymonkey;7929550

    I think if you run it, you'll find out. Surely the point of these … 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
    Avatar
    @
      Text
      Top Discussions
      1. Do cheeky drivers annoy you when they park outside your house and leave it …2240
      2. Just heard this...2 ★★★★★★★★★★★★★★ congrats to all on 392k ★★★★★★★★★★★★★★7767346
      3. What would be HELL to you?2634
      4. Tesco vouchers?11

      See more discussions