-1
SELECT SUM(T.KDV) AS TOTALKDV
FROM   (SELECT *
    FROM pharmana_urun_db.general_Table, pharmana_Hareket_db.general_Table
    WHERE pharmana_urun_db.general_Table.Barkod = pharmana_Hareket_db.general_Table.Barkod AND  pharmana_Hareket_db.general_Table.EczaneID = '".$pharmacy_id"') AS T
GROUP BY T.Kategori

1060 - Duplicate column name 'Barkod',

how can I avoid this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
c lover
  • 1
  • 1
  • Start using modern explizit join syntax – Jens Aug 22 '17 at 10:18
  • Because you have multiple fields called Barkod. You need to be explicit instead of the `SELECT * FROM` and rename/alias any columns that have the same name. – ssn Aug 22 '17 at 10:20

2 Answers2

0

(SELECT * FROM pharmana_urun_db.general_Table, pharmana_Hareket_db.general_Table

This selects two columns with the same name Barkod

You need to use the explicit join syntax as Jens suggested

Nice explanation here

Ulug Toprak
  • 1,172
  • 1
  • 10
  • 21
0

Learn to use proper JOIN syntax. Don't use subqueries unnecessarily.

You should write this query as:

SELECT SUM(T.KDV) AS TOTALKDV
FROM pharmana_urun_db.general_Table gt1 JOIN
     pharmana_Hareket_db.general_Table gt2
     USING (Barkod)
WHERE gt2.EczaneID = '".$pharmacy_id"'
GROUP BY Kategori;

You should also learn to use parameters to pass values into SQL queries, rather than munging query strings. I also suspect that you should be including Kategori in the SELECT.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786