大家好,我有一个查询结果,给我2个元素开始相同但结尾不同,这样:
通过php函数我可以消除差异,但是echo仍然给了我2个元素,我怎样才能将它们组合成一个元素:
(我在查询中尝试过GROUP BY,但这没有用,因为在db名称不同时)
这是我的代码:
<?php
$result0 = mysqli_query($dbiac, "SELECT * FROM corpus_info WHERE corpus IN (SELECT corpus FROM corpus_alignments)") or die(mysqli_error($dbiac));
while($cpsblg = mysqli_fetch_array($result0)){
// eliminate the difference and echo it to the page
$cpsblg = preg_replace('"_(de|en|ca|es|fr|it|pt)$"', '', $cpsblg['corpus']);
echo $cpsblg."<br />";
?>
结果:
答案 0 :(得分:1)
你不能这样做吗?
SELECT c.corpus_initial
FROM (SELECT SUBSTRING_INDEX(corpus, '_', 1) AS corpus_initial
FROM corpus_info
WHERE corpus IN (SELECT corpus FROM corpus_alignments)) c
GROUP BY c.corpus_initial