Mysql加入限制

Mysql加入限制,mysql,Mysql,我的问题是这样的 SELECT tb1.name, COUNT(tb2.payment_date) as first_payment FROM table1 LEFT JOIN table2 tb2 ON tb2.id_user = tb1.id +-----------+-------------+ | Name | Count | +-----------+-------------+ | John | 543534543 | 但我希望我的查询返回一个

我的问题是这样的

SELECT tb1.name, COUNT(tb2.payment_date) as first_payment FROM table1 LEFT JOIN table2 tb2 ON tb2.id_user = tb1.id

+-----------+-------------+
| Name      |  Count      |
+-----------+-------------+
| John      |   543534543 |
但我希望我的查询返回一个连接限制,比如:

LEFT JOIN tb2 ON tb2.id_user = tb1.id { LIMIT JOIN }
只返回一个关系

+-----------+-------------+
| Name      |  Count      |
+-----------+-------------+
| John      |   3         |

如何限制join中查询的关系…限制的目的是什么?只取最大、最小、任何付款日期?我只需要第一个付款日期Igor:你能提供一些样本数据和期望的结果集吗?如果你只需要第一个付款日期,那么为什么要选择付款日期。它必然会将结果合并为单个记录,您还需要什么
SELECT 
    tb1.name, 
    COUNT(tb2.payment_date) as first_payment 
FROM table1 
LEFT JOIN (SELECT id_user , MIN(id) FROM table2 GROUP BY id_user)as tb2 ON tb2.id_user = tb1.id
select tb1.name, count(*) as first_payment
from table1 t1
LEFT JOIN (SELECT id_user, min(payment_date) 
           FROM table2
           GROUP BY id_user) as t2
ON t1.id = t2.id_user
GROUP BY tb1.name