<?
$strSQL = "SELECT detail.ThaiName,tel.tel FROM detail LEFT JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.Enable='T' AND detail.IsActive='T' GROUP BY detail.ThaiName, tel.tel";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo $strSQL;
while($objResult = mssql_fetch_array($objQuery))
{
echo "<br>";
echo $objResult["ThaiName"].$objResult["tel"];
}
?>
เหมือนเดิมครับ
SELECT DISTINCT(tel.id_detail),tel.tel,detail.ThaiName FROM detail LEFT JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.Enable='T' AND detail.IsActive='T'
SELECT DISTINCT(tel.id_detail),tel.tel,detail.ThaiName FROM detail INNER JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.Enable='T' AND detail.IsActive='T'
SELECT detail.ThaiName, tel.tel FROM detail INNER JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.Enable='T' AND detail.IsActive='T' GROUP BY detail.ThaiName
error ครับ มันบอกต้องใส่ tel.tel ที่ group by ด้วย
SELECT detail.ThaiName, tel.tel FROM detail INNER JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.Enable='T' AND detail.IsActive='T' GROUP BY detail.ThaiName,tel.tel
ผมก็ใส่ไปละ และแล้วมันก็เหมือนเดิมครับ T_T
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for detail
-- ----------------------------
DROP TABLE IF EXISTS `detail`;
CREATE TABLE `detail` (
`id_detail` int(11) NOT NULL auto_increment,
`thainame` text,
`enable` text,
`active` text,
PRIMARY KEY (`id_detail`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of detail
-- ----------------------------
INSERT INTO `detail` VALUES ('1', 'AAA', 'T', 'T');
INSERT INTO `detail` VALUES ('2', 'BBB', 'T', 'T');
INSERT INTO `detail` VALUES ('3', 'CCC', 'N', 'N');
INSERT INTO `detail` VALUES ('4', 'DDD', null, null);
INSERT INTO `detail` VALUES ('5', 'EEE', null, null);
Code (PHP)
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for tel
-- ----------------------------
DROP TABLE IF EXISTS `tel`;
CREATE TABLE `tel` (
`id_tel` int(10) NOT NULL auto_increment,
`tel` text,
`id_detail` int(10) default NULL,
PRIMARY KEY (`id_tel`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of tel
-- ----------------------------
INSERT INTO `tel` VALUES ('1', '085-111-2222', '1');
INSERT INTO `tel` VALUES ('2', '084-222-3333', '1');
INSERT INTO `tel` VALUES ('3', '085-333-4444', '1');
INSERT INTO `tel` VALUES ('4', '086-234-5678', '2');
INSERT INTO `tel` VALUES ('5', '088-999-5566', '1');
INSERT INTO `tel` VALUES ('6', '087-555-1111', '3');
INSERT INTO `tel` VALUES ('7', '082-111-3333', '3');
มีฟิว detail.enable และ detail.active
SELECT detail.thainame, tel.tel FROM detail INNER JOIN tel ON detail.id_detail=tel.id_detail WHERE detail.enable = 'T' AND detail.active = 'T' GROUP BY thainame