Avatar of MrTV
MrTV
Flag for Thailand asked on

sql statement mysql joint to table and sum

i have 2  table sale , and payment how can i joint to table when iI sale customer sometime paymeny time for some item so i should have table payment to record it  how can i write sql statement like merk statement

sale.preselRef    sale.name  sale.grandtotal   sum from table payment group by saleid (match with sale.preselRef )
-- Table structure for table `sale`
--

CREATE TABLE IF NOT EXISTS `sale` (
  `preselRef` int(12) NOT NULL,
  `nameid` int(11) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
     -----
   `grandtotal` decimal(10,2) DEFAULT NULL,


CREATE TABLE IF NOT EXISTS `payment` (
  `id` int(11) NOT NULL,
  `saleid` int(11) NOT NULL,
  `type` varchar(80) COLLATE utf8_bin NOT NULL,
  `amount` decimal(11,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

Open in new window

PHPSQL

Avatar of undefined
Last Comment
Sharath S

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sharath S

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck