更新 - 没关系,我用PHP端修复它并使用" distinct"最终的查询(解决方案)是这样的:
SELECT Distinct m.idDenuncia FROM denunciaMedicamentos AS m JOIN denuncias AS p WHERE p.id = m.idDenuncia ORDER BY m.medicamento
SELECT * FROM denunciaMedicamentos AS m
JOIN denuncias AS p
WHERE p.id=m.idDenuncia
ORDER BY m.medicamento
它有效,但它会重复列id
和idDenuncia
。这是结果:
idDenuncia
是对denuncias表的引用。
我想知道,我该怎么做才能重复数据(id
)?
答案 0 :(得分:1)
从一个表中选择所有表并从另一个表中选择将解决您的问题
SELECT m.*,p.col1,p.col2 FROM denunciaMedicamentos AS m JOIN denuncias AS p WHERE p.id=m.idDenuncia ORDER BY m.medicamento
答案 1 :(得分:0)
现在,我明白了,你不希望128在你的结果中重复。如果这是您想要使用的:
SELECT distinct(m.idDenuncia) FROM denunciaMedicamentos AS m JOIN denuncias AS p WHERE p.id=m.idDenuncia ORDER BY m.medicamento