在一个查询中获取5个表数据...没有连接...没有关系

I have 5 tables or more for a logs.

  1. tbl_product_log
  2. tbl_user_log
  3. tbl_customer_log
  4. tbl_vendor_log
  5. tbl_quotations_logs

They have no relation with each other. But they have same hierarchy of columns.

  1. logid
  2. logdetails
  3. 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.

  1. All Logs
  2. Product Logs
  3. User Logs
  4. Customer Logs
  5. Vendor Logs
  6. Quotation Logs

Like this

enter image description here

In Every tab e.g. (products logs, user logs, customer logs ....) I get all there log data successfully.

enter image description here

enter image description here

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

enter image description here

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