简体   繁体   中英

MySql - How to select MAX ID from two tables with WHERE clause

I have two tables invoice and invoice_customer. Both have column invoice_id like (0000125) and firma_id (firma_id is a company_id) How can i select max invoice_id of two tables with using WHERE caluse? i done query for single table only

SELECT MAX(invoice_id) AS maxID FROM invoice WHERE firma_id = 13

I done this way

SELECT MAX(invoice_id) maxID
FROM
(
  SELECT invoice_id FROM invoice WHERE firma_id = 13
  UNION ALL
  SELECT invoice_id FROM invoice_customers WHERE firma_id = 13
) test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM