关于表的过滤的查询,需要没有重复的表

时间:2013-10-23 07:16:28

标签: mysql

我如何编写一个不会使用mysql给我重复的查询?我的结果表不应包含重复项。

第一个查询是:

SELECT ord_no,name, mobile, address,  rate, mrp,
       create_date, edited_date,status
FROM orders o, customer c
where o.cust_id = c.id and status = 'CHECKED' 
  AND DATEDIFF(CURDATE(), edited_date) between 2 and 3 
order by 1;

第二个查询是:

SELECT ord_no,name, mobile, address,  rate, mrp, 
      create_date, edited_date,status
FROM orders o, customer c
where o.cust_id = c.id and status = 'CHECKED' 
  AND edited_date<DATE_SUB(now(),interval 48 hour) 
order by 1;

如何过滤它?

1 个答案:

答案 0 :(得分:0)

尝试GROUP BY

SELECT ord_no,name, mobile, address,  rate, mrp,
   create_date, edited_date,status
FROM orders o, customer c
where o.cust_id = c.id and status = 'CHECKED' 
AND DATEDIFF(CURDATE(), edited_date) between 2 and 3
 GROUP BY ord_no,name, mobile, address,  rate, mrp,
   create_date, edited_date,status 
order by 1;

您可以指定您想要的某个字段是否唯一吗?否则这应该有用。