簡體   English   中英

MySql - 如何使用 WHERE 子句從兩個表中獲取 select MAX ID

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

我有兩張表 invoice 和 invoice_customer。 兩者都有列 invoice_id,如 (0000125) 和firma_id(firma_id 是 company_id)我如何使用 WHERE caluse 對兩個表進行 select max invoice_id ? 我只查詢了單個表

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

我是這樣做的

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM