Mysql – how to get data from two tables in thesql query with where Pk of one table is set as foreign key on PK column for other table

foreign keyjavajoin;MySQLquery

enter image description here

The query I am using to retrieve data is as

"select sum(totalbill) as tbdb, sum(discinamount) as tddb, sum (billafterdisc) as tbaddb,"
+ " sum(totalqt) as tqdb,"
+ " sum(payed) as tpdb,"
+ " sum(balance) as tbaldb,"
+ " `customer`"
+ " from `orderacc` join `orders` using (`orderaccid`)"
+ " group by `customer` order by max(`date`) DESC";

I am getting error that orderaccid is not a column in clause.

Best Answer

Well, your orders table doesn't have a column orderaccid. You can use using only when the column names are equal. Use this instead:

from orderacc join orders on orderacc.orderaccid = orders.orderid