I've got a query that's connected to a table which I only want to see the last entered result based on the dtm.
This is my query:
CREATE OR REPLACE VIEW vwc_students AS
SELECT u_students.stud_id,u_students.stud_firstname, u_students.stud_middlename,u_students.stud_lastname, CONCAT_WS(' ',u_userse.user_firstname,u_userse.user_lastname) AS stud_editeduser, u_students.stud_edited, u_tbleeditlog.editedDtm
FROM u_students
JOIN u_studsites ON u_studsites.uss_studid = u_students.stud_id
JOIN u_locations ON u_locations.loc_id = u_students.stud_base
JOIN u_users ON u_users.user_id = u_students.stud_loggedid
LEFT JOIN (SELECT editedID, editedDtm FROM u_tbleeditlog WHERE editSite = 1 AND editType = 1 ORDER BY editedDtm DESC LIMIT 1) u_tbleeditlog ON u_tbleeditlog.editedID = u_students.stud_id
LEFT JOIN u_users AS u_userse ON u_userse.user_id = u_tbleeditlog.editedID
WHERE u_studsites.uss_siteid = '1'
but I'm getting the error #1349 - View's SELECT contains a subquery in the FROM clause
I got the code examples from Limiting a left join to returning one result? and MySQL JOIN Multiple Tables With LIMIT Last Table By DateTime per result
Is what I am trying to do possible, and if so how?
Update
I now have the following two views as suggested:
CREATE OR REPLACE VIEW vwc_students AS
SELECT u_students.stud_id,u_students.stud_firstname, u_students.stud_middlename,u_students.stud_lastname, u_userse.editedEditor AS stud_editeduser, u_userse.editedDtm AS stud_edited
FROM u_students
JOIN u_studsites ON u_studsites.uss_studid = u_students.stud_id
JOIN u_locations ON u_locations.loc_id = u_students.stud_base
JOIN u_users ON u_users.user_id = u_students.stud_loggedid
LEFT JOIN vwu_editlog AS u_userse ON u_userse.editTypeID = u_students.stud_id AND u_userse.editType = 1
WHERE u_studsites.uss_siteid = '1'
and
CREATE OR REPLACE VIEW vwu_editlog AS
SELECT u_tbleeditlog.*, CONCAT_WS(' ',u_users.user_firstname,u_users.user_lastname) AS editedEditor
FROM u_tbleeditlog
JOIN u_users ON u_users.user_id = u_tbleeditlog.editedID
ORDER BY u_tbleeditlog.editedDtm DESC LIMIT 1
But this last view is limiting the entire thing to 1 result! How would I limit each unique ID to 1? I also get the message Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
, even though in the original table it is there.