I have 5 tables or more for a logs.
- tbl_product_log
- tbl_user_log
- tbl_customer_log
- tbl_vendor_log
- tbl_quotations_logs
They have no relation with each other. But they have same hierarchy of columns.
- logid
- logdetails
- logdatetime
Every time when, there is something happened in these tables (e.g. 'insert','delete',update) a record inserted in relative table for a log.
Now I want to show all logs in one page. There are 6 tabs in it.
- All Logs
- Product Logs
- User Logs
- Customer Logs
- Vendor Logs
- Quotation Logs
Like this
In Every tab e.g. (products logs, user logs, customer logs ....)
I get all there log data successfully.
Now I want to show all logs data in All
tab like in other tabs.
I tried query by my own but it shows me every thing separately.
Here is my query
SELECT * FROM tbl_product_log, tbl_user_log, tbl_customer_log, tbl_vendor_log, tbl_quotations_logs Limit 20
And here is result
So please tell me how can I achieve this, that all logs data show in All tab
only in three columns like other tabs show the result with one query.
Hop you understand my question.
use union to connect all tables
(Select * From tbl_product_log LIMIT 5)
union
(Select * From tbl_user_log LIMIT 5)
union
(Select * From tbl_customer_log LIMIT 5)
union
(Select * From tbl_vendor_log LIMIT 5)
union
(Select * From tbl_quotation_log LIMIT 5);
notes : this query will produce a total of 25 records
Try to use UNION instead
SELECT * FROM
(SELECT logid, logdetails,logdatetime, '1' as identifier FROM tbl_product_log) as a
UNION ALL
(SELECT logid, logdetails,logdatetime, '2' as identifier FROM tbl_user_log) as b
UNION ALL
(SELECT logid, logdetails,logdatetime, '3' as identifier FROM tbl_customer_log) as c
UNION ALL
(SELECT logid, logdetails,logdatetime, '4' as identifier FROM tbl_vendor_log) as d
UNION ALL
(SELECT logid, logdetails,logdatetime, '5' as identifier FROM tbl_quotations_logs) as e
-- WHERE indentifier = '' //in here you can put here to filter what report you wanted to appear
ORDER BY logid // Order it by Logid
LIMIT 20 //change the limit
Put an identifier on each table you combine with other so you still have a control where that data came from.
Try this one
SELECT * FROM (SELECT logid, logdetails,logdatetime, '1' as identifier
FROM tbl_product_log
UNION ALL
SELECT logid, logdetails,logdatetime, '2' as identifier FROM tbl_user_log
UNION ALL
SELECT logid, logdetails,logdatetime, '3' as identifier FROM tbl_customer_log
UNION ALL
SELECT logid, logdetails,logdatetime, '4' as identifier FROM tbl_vendor_log
UNION ALL
SELECT logid, logdetails,logdatetime, '5' as identifier FROM tbl_quotations_logs ) as a
-- WHERE indentifier = '' -- in here you can put here to filter what report you wanted to appear
ORDER BY logid -- Order it by Logid
LIMIT 20 -- change the limit