I have the following mysql table fields
|action_id|timestamp|user|module|action|object|info|interface|
Content of which are below:
69 |2021-12-06 22:15:43|1 |CATALOGUING|ADD|24 |item |intranet
122058|2022-02-23 09:47:17|13|CATALOGUING|ADD|10338|biblio|intranet
Here is the mysql query that I am working on:
SELECT action_id, i.barcode, CONCAT('<a href=\"/cgi-bin/koha/catalogue/detail.pl?biblionumber=',biblio.biblionumber,'\">',b.title,'</a>') AS Title, biblio.author, al.timestamp, CONCAT('<a href=\"/cgi-bin/koha/members/moremember.pl?borrowernumber=',borrowers.borrowernumber,'\">',borrowers.surname, ', ', borrowers.firstname,'</a>') AS Librarian, i.permanent_location, (CASE WHEN al.info LIKE "biblio%" THEN 'biblio' ELSE 'item' END) as typeofentry, al.action as type_of_action, al.info from action_logs AS al LEFT JOIN borrowers ON al.user =
CASE WHEN al.info LIKE "biblio%" THEN
borrowers.borrowernumber LEFT JOIN biblio on al.object=biblio.biblionumber
ELSE borrowers.borrowernumber LEFT JOIN items AS i on al.object=i.itemnumber LEFT JOIN biblio on i.biblionumber=biblio.biblionumber
END
I am trying to use CASE WHEN for LEFT JOIN such that if the "info" column is biblio, the query should left join with biblio and ignores LEFT JOIN with item table. If the "info" column is item, then it should LEFT JOIN with item then LEFT JOIN with biblio. Is this even possible with LEFT JOIN. This is what I have been trying to emulate: How to use a case statement to determine which field to left join on