![]() The query below should function no differently if UNION ALL were used rather than UNION because it is not going to return any duplicates. The first block below will show blanks for books borrowed but not returned.Īlso UNION ALL will simply retain duplicate lines versus discarding them. If you don't care about that then the last response by Gordon would be fine. I am assuming that you want borrow/return date detail to be on every row. Because you are merging 2 different date values into the same column you will want to distinguish between which rows reflect a return vs. I tried to simply combine the queries like this: SELECT a.isbn, a.member_id, a.staff_id, b.staff_id,īut it says "Subquery returns more than 1 row" and I still can't seem to do it after lots of thorough Google-ing. But I need these to be in one query only. ![]() Now I tried to use UNION on them by testing if it also gives me what I need and so I used: SELECT date_borrowed FROM tblborrowĪnd it has indeed. ![]() It has given me what I need except the date_returned and date_borrowed are displayed in separate columns, of course. I have done displaying them with left join using this: SELECT a.isbn, a.member_id, a.staff_id, a.date_borrowed, b.staff_id, b.date_returnedįROM tblborrow AS a left join tblreturn AS b on a.borrow_id = b.borrow_id It’s also possible to have all the complex queries/operations in the SELECT queries and perform UNION with other SELECT statements to yield a combined result. My tblborrow contains the following columns: MySQL UNION is used to combine results from multiple SELECT queries into a single result set. Now, what I am trying to do is to display almost all my columns from both tblborrow and tblreturn, in order by their date_borrowed and date_returned in union. I have two tables named tblborrow and tblreturn wherein they both have date columns.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |