There are three tables:
tblAccommodation table
-------------- -----------------------
fldProductID fldAccommodationName
-------------- -----------------------
tblAccommodation table
------------- -------------------- ---------------------
fldProductID fldAccommodationText fldAccommodationText1
------------- -------------------- ---------------------
tblAccommodation table
------------ --------
fldProductID seo_url
------------ --------
three table join query with distinct
$sql = "SELECT
DISTINCT
tblAccommodation.fldProductID,
tblAccommodationText.fldAccommodationTextTitle,
seo_url,
tblAccommodation.fldAccommodationName
FROM tblAccommodation
LEFT JOIN tblAccommodationText
ON tblAccommodationText.fldProductID = tblAccommodation.fldProductId
LEFT JOIN tblProduct
ON tblProduct.fldProductID = tblAccommodation.fldProductID
WHERE
seo_url = 'yacht-4'";
code result
------------ ------------------------- ------- -------------------- fldProductID fldAccommodationTextTitle seo_url fldAccommodationName ------------ ------------------------- ------- -------------------- 6 Dolphin Villas yacht-4 yacht 4 upper cabin 6 Aqua Suite yacht-4 Aqua Suite with Pool 6 Dolphin Villas yacht-4 yacht 4 upper cabin 6 Aqua Suite yacht-4 Aqua Suite with Pool
why repeat same value twice please help me
You can use the GROUP BY
SELECT tblAccommodation.fldProductID,fldAccommodationText1,tblAccommodationText.fldAccommodationTextTitle,seo_url,tblAccommodation.fldAccommodationName
FROM tblAccommodation
LEFT JOIN tblAccommodationText ON tblAccommodationText.fldProductID = tblAccommodation.fldProductID
LEFT JOIN tblProduct ON tblProduct.fldProductID = tblAccommodation.fldProductID
WHERE seo_url='yacht-4'
GROUP by tblAccommodationText.fldAccommodationTextTitle
code is work firstly i remove distinct and add after group by function ....
correct query is $sql = "SELECT tblAccommodation.fldProductID,fldAccommodationText1,tblAccommodationText.fldAccommodationTextTitle,seo_url,tblAccommodation.fldAccommodationName FROM tblAccommodation LEFT JOIN tblAccommodationText ON tblAccommodationText.fldProductID = tblAccommodation.fldProductID LEFT JOIN tblProduct ON tblProduct.fldProductID = tblAccommodation.fldProductID where seo_url='yacht-4' GROUP by tblAccommodationText.fldAccommodationTextTitle"
tblAccommodation table
-------------- ----------------------- fldProductID fldAccommodationName -------------- ----------------------- 6 yacht 4 upper cabin 6 Aqua Suite with Pool
tblAccommodationText table
-------------- --------------------- ------------------------ fldProductID fldAccommodationText fldAccommodationText1 -------------- --------------------- ------------------------ 6 Dolphin Villas king sized bed overlooking the ocean... 6 Aqua Suite sundeck with lagoon access where you...
tblProduct table
-------------- -------- fldProductID seo_url -------------- -------- 6 yacht-4 6 yacht-4
expected table
------------ ---------------------------- -------------------- -------- fldProductID fldAccommodationText1 fldAccommodationText seo_url ------------ ----------------------------- -------------------- -------- 6 king sized bed overlooking the ocean... Dolphin Villas yacht-4 6 sundeck with lagoon access where you... Aqua Suite yacht-4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.