我有三个表table_1、table_2和table_3,它们都有一个公共列comm_name作为外键。我想通过连接这三个表来找到列data_id的最大值。使用条件是comm_name。
简而言之:合并这三个表并找到最大的data_id,即返回9
我尝试了以下方法:
SELECT max(data_id) FROM (( SELECT table_1.data_id FROM table_1 where comm_name='aa') UNION(SELECT table_2.data_id FROM table_2 where comm_name='aa') UNION(SELECT table_3.data_id FROM table_2 where comm_name='aa'));
但是它显示错误
An expression was expected. (near "(" at position 26)
Unexpected token. (near "(" at position 26)
Unexpected token. (near "(" at position 27)
This type of clause was previously parsed. (near "SELECT" at position 29)
This type of clause was previously parsed. (near "SELECT" at position 125)
This type of clause was previously parsed. (near "SELECT" at position 220)