百分求SQL语句
DROP TABLE IF EXISTS `customertemplate`;
CREATE TABLE IF NOT EXISTS "customertemplate " (
"CID " int(11) NOT NULL,
"CustomerID " int(11) NOT NULL,
"TemplateID " int(11) NOT NULL,
"TemplateType " varchar(10) NOT NULL,
PRIMARY KEY ( "CID ")
) AUTO_INCREMENT=7 ;
--
-- Dumping data for table `customertemplate`
--
INSERT INTO `customertemplate` (`CID`, `CustomerID`, `TemplateID`, `TemplateType`) VALUES
(1, 8, 1, '1 '),
(2, 8, 2, '2 '),
(3, 8, 3, '1 '),
(4, 8, 4, '2,3 '),
(6, 7, 4, '1 ');
-- --------------------
--
-- Table structure for table `template`
--
DROP TABLE IF EXISTS `template`;
CREATE TABLE IF NOT EXISTS "template " (
"TemplateID " int(11) NOT NULL,
"TemplateName " varchar(30) NOT NULL,
"TemplateFileName " varchar(150) NOT NULL,
PRIMARY KEY ( "TemplateID ")
) AUTO_INCREMENT=6 ;
--
-- Dumping data for table `template`
--
INSERT INTO `template` (`TemplateID`, `TemplateName`, `TemplateFileName`) VALUES
(1, 'Gloveco ', 'Gloveco '),
(2, 'Medline ', 'Medline '),
(3, 'MedLine Invoice ', 'invoice_medline '),
(4, 'MedLine PackingList ', 'PackingList_medline '),
(5, 'Delivery Order ', 'Delivery Order ');
select * from template t left join customertemplate ct on t.TemplateID=ct.TemplateID where ct.CustomerID=8
这样只能查询出来id=8的。
我要显示所有的template,以及在ct表里有的数据,,
TemplateName TemplateFileName CID CustomerID TemplateID TemplateType
Gloveco Gloveco 1 8 1 1
Medline Medline 2 8 2 2
MedLine Invoice invoice