0

我正在尝试从 5 个表中获取记录,最后我已经完成了,但现在我想要唯一的记录,那么我应该在查询中更改什么?

SELECT
  t.*,
  sh.invoice_Number AS sale_inv_no,
  sh.invoice_date AS sale_inv_date,
  sh.from_Date AS sale_from,
  sh.to_Date AS sale_to,
  sh.number_Of_Months AS sale_nom,
  c.cName AS cust_name,
  h.hName AS ho_name,
  [hSize1] & 'X' & [hSize2] & '=' & [hSize_SQF] AS ho_size,
  h.hLocation AS ho_loc,
  c.cMobile AS cust_mob,
  f.firmName AS firm_name
FROM
  (
    (
      (
          adv_tbl_transactions AS t
       RIGHT JOIN
          adv_tbl_Sale_Hoardings AS sh
       ON t.tra_code = sh.transaction_code
      ) LEFT JOIN adv_tbl_Hoardings AS h
        ON sh.hid = h.ID
    ) LEFT JOIN tbl_Firms AS f
      ON sh.e_fid = f.ID
  ) LEFT JOIN tbl_Customers AS c
    ON sh.cid = c.ID
WHERE
  (((t.e_fid)=1));

它给了我如下输出

srNo | Hoarding    | customers   |  transaction details  | advance  | balance | total
1    | Name: h1    | Cust1       |  inv no : 1           | 6000     | 1000    | 70000
2    | Name: h1    | Cust1       |  inv no : 1           | 6000     | 1000    | 70000
3    | Name: h2    | Cust2       |  inv no : 2           | 3000     | 1000    | 40000
4    | Name: h2    | Cust2       |  inv no : 2           | 3000     | 1000    | 40000

我想输出如下

srNo | Hoarding    | customers   |  transaction details  | advance  | balance | total
1    | Name: h1    | Cust1       |  inv no : 1           | 6000     | 1000    | 70000
2    | Name: h2    | Cust2       |  inv no : 2           | 3000     | 1000    | 40000

我想要 distict 列 entry_no

4

1 回答 1

0

使用distinct关键字:

select distinct t.*,
       sh.invoice_Number AS sale_inv_no,
       sh.invoice_date AS sale_inv_date,
       sh.from_Date AS sale_from,
       sh.to_Date AS sale_to,
       sh.number_Of_Months AS sale_nom,
       c.cName AS cust_name,
       h.hName AS ho_name,
       [hSize1] & 'X' & [hSize2] & '=' & [hSize_SQF] AS ho_size,
       h.hLocation AS ho_loc,
       c.cMobile AS cust_mob,
       f.firmName AS firm_name
FROM (((adv_tbl_transactions AS t 
        RIGHT JOIN adv_tbl_Sale_Hoardings AS sh 
        ON t.tra_code = sh.transaction_code)
        LEFT JOIN adv_tbl_Hoardings AS h
        ON sh.hid = h.ID)
        LEFT JOIN tbl_Firms AS f ON sh.e_fid = f.ID)
        LEFT JOIN tbl_Customers AS c
        ON sh.cid = c.ID
WHERE (((t.e_fid)=1)) ; 
于 2013-10-21T12:18:09.220 回答