这是一个选择查询...
$q = "SELECT
tcs.tutor_id AS tid,
tcs.category_id AS cid,
tcs.subject_id AS sid,
GROUP_CONCAT( DISTINCT s.subjects SEPARATOR ', ') AS subjects,
t.tutor_name AS tname,
t.tutor_code AS tcode,
DATE_FORMAT(t.registration_date, '%b %D, %Y') AS date,
t.qualification AS qualifi,
GROUP_CONCAT( DISTINCT o.option_name SEPARATOR ', ') AS tutor_option,
timg.image_name AS img,
city_name AS city,
d.district_name AS district
FROM tutor_category_subject as tcs
INNER JOIN subject AS s ON tcs.subject_id = s.subject_id
INNER JOIN tutor_option AS toption ON toption.tutor_id = tcs.tutor_id
INNER JOIN options AS o ON toption.option_id = o.option_id
INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id
INNER JOIN address ON address.address_id = t.address_id
INNER JOIN city ON city.city_id = address.city_id
INNER JOIN district AS d ON d.district_id = city.district_id
LEFT JOIN tutor_images AS timg ON timg.tutor_id = tcs.tutor_id AND timg.image_type = 'profile'
WHERE s.subjects LIKE '%$subject%'
GROUP BY tcs.tutor_id";
此查询现在正在运行..现在我发现了一个问题。这是.....很多主题可能需要一个特定的导师。我需要选择与教师有关的所有主题,并使用搜索关键字来显示搜索结果。在此查询中,搜索关键字是' $ subject'。 此查询仅选择与给定关键字类似的导师的主题。例如,如果用户提供的关键字类似于' business'查询选择该导师的科目,如商业研究,商业会计等,只有'。所以我也需要通过这个查询选择其他主题..任何人都可以帮助我吗?
谢谢你。答案 0 :(得分:0)
嗯,我不是MySQL大师,但我认为你不需要选择
tcs.category_id AS cid,
tcs.subject_id AS sid,
您还需要使用distinct
关键字
SELECT distinct
tcs.tutor_id AS tid,
GROUP_CONCAT( DISTINCT s.subjects SEPARATOR ', ') AS subjects,
t.tutor_name AS tname,
t.tutor_code AS tcode,
DATE_FORMAT(t.registration_date, '%b %D, %Y') AS date,
t.qualification AS qualifi,
GROUP_CONCAT( DISTINCT o.option_name SEPARATOR ', ') AS tutor_option,
timg.image_name AS img,
city_name AS city,
d.district_name AS district
FROM tutor_category_subject as tcs
INNER JOIN subject AS s ON tcs.subject_id = s.subject_id
INNER JOIN tutor_option AS toption ON toption.tutor_id = tcs.tutor_id
INNER JOIN options AS o ON toption.option_id = o.option_id
INNER JOIN tutors AS t ON tcs.tutor_id = t.tutor_id
INNER JOIN address ON address.address_id = t.address_id
INNER JOIN city ON city.city_id = address.city_id
INNER JOIN district AS d ON d.district_id = city.district_id
LEFT JOIN tutor_images AS timg ON timg.tutor_id = tcs.tutor_id AND timg.image_type = 'profile'
WHERE s.subjects LIKE '%$subject%'
GROUP BY tcs.tutor_id