MySQL Forums
Forum List  »  Newbie

query Selecting Last entry per computer for a group from two tables. Urgent Help please.
Posted by: Mark Joe
Date: April 11, 2018 11:09PM

Dear All,

I am new to Database and I was given a task at work to improve an open source system that's been designed by someone else.

Any help WILL be Really much much appreciated.


I have a similar scenario but with much more fields in each table, but what is needed is a query to show this

Result:



| Computer_Name | Last Entry | Status |
--------------------------------------------
| COMP3 | 12:30 AM |Returned |
| COMP2 | 11:00 AM |Borrowed |
| COMP1 | 9:30 AM |Returned |

So I need to show the latest entry only for each computer from table 2 "Booking".

========================================================================================

Database structure (Cant change it):



Table 1: Computer
__________________

(PK)

| ID | Computer_Name |
----------------------
| 50 | COMP1 |
| | |
| 60 | COMP2 |
| | |
| 70 | COMP3 |
| | |
| | |






Table 2: Booking
_______________

(PK) (FK (PK for
Computers
Table 1 ))

| ID | Computer_ID | Entries | Status |
---------------------------------------------
| 100 | 70 | 12:30 AM |Returned
| | | |
| 200 | 70 | 12:00 AM |Borrowed
| | | |
| 300 | 60 | 11:00 AM |Borrowed
| | | |
| 400 | 60 | 10:00 AM |Booked
| | | |
| 500 | 50 | 9:30 AM |Returned
| | | |
| 600 | 50 | 9:00 AM |Borrowed
| | | |
| | | |


Please Help me Gent as I am really lost.



Kind regards.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.