读书人

请问一个连接查询

发布时间: 2012-01-15 22:57:49 作者: rapoo

请教一个连接查询
select * from tableA

+----+----------------+---------+
| id | v_code | inAmount|
+----+----------------+---------+
| 1 | 140906020005 | 100.00 |
+----+----------------+---------+

select * from tableB

+----+----------------+-------+-------------+
| id | v_code | price | v_status |
+----+----------------+-------+-------------+
| 1 | 140906020005 | 100 | 10 |
| 2 | 140906020005 | 200 | -30 |
+----+----------------+-------+-------------+


用连接查询
select f.* from
tableA as f inner join tableB as s on f.v_code=s.v_code
where
and f.inAmount> 0
and s.v_status in (10,-30)
查询出来的是2条记录,重复了一条,如何能过滤掉重复的记录

[解决办法]
说明下你的查询目的

先可以这样
select distinct f.* from
tableA as f inner join tableB as s on f.v_code=s.v_code
where
and f.inAmount> 0
and s.v_status in (10,-30)

读书人网 >SQL Server

热点推荐