首页 > 解决方案 > 如何从sql中的相同值中选择1条记录?

问题描述

我有一张customer桌子:

我必须显示客户姓名才能选择出售。名称可以重复,我必须选择带有客户名称的记录。如何选择该特定记录?

我正在使用以下查询:

select tot_amt 
from customer  
where cust_name = 'someone'

标签: sql

解决方案


虽然您应该使用cust_id来显示结果,因为每个结果cust_id都是唯一的,但是如果您只想显示 1 row,即使结果中rows有超过1 个,那么您可以使用query

select top 1 tot_amt from customer where cust_name='someone';

推荐阅读