简体   繁体   English

MySQL-在一个字段中显示多行(带有内部联接的表)

[英]MySQL - Display multiple rows in one field (tables with inner joins)q

I have a mysql database with 3 tables, one table is called fixturechannels, one is called footballfixtures, and one is called satellite. 我有一个包含3个表的mysql数据库,一个表称为fixturechannels,一个表称为footballfixtures,一个表称为Satellite。

Basically the satellite table contains information about satellite channels (name, country, channelid), footballfixtures contains (matchid, hometeam, awayteam, competition....), and fixturechannels is a table containing (matchid, and channelid, these are linked by foriegn keys from the satellite and footballfixtures table respectively). 基本上,附属表包含有关卫星频道(名称,国家/地区,频道ID)的信息,足球装备包含(比赛ID,主队,客队,比赛...),而FixtureChannels是包含(比赛ID和频道ID的)表,这些链接由foriegn链接分别来自Satellite和Footballfixtures表中的密钥)。

Below are further details on the tables: 以下是表格的更多详细信息:

tablelayouts 餐桌布置

I used the following query below, and it worked, I was able to echo the details I need from the table 我在下面使用了以下查询,并且可以正常工作,我能够从表中获取所需的详细信息

"SELECT * FROM fixturechannels INNER JOIN footballfixtures ON fixturechannels.matchid=footballfixtures.matchid INNER JOIN satellite ON fixturechannels.channelid=satellite.channelid";

The code used for echoing the details is: 用于回显详细信息的代码是:

 <tbody><tr>
            <th>Match ID</th>
            <th>Home Team</th>
            <th>Away Team</th>
            <th>Competition</th>
            <th>Date</th>
            <th>Time</th>
            <th>Channel ID</th>
            <th>Channel Name</th>


                </tr>
                <?php foreach ($results as $res) { ?>
                <tr>
               <td><?php echo $res["matchid"]; ?></td>
               <td><?php echo $res["hometeam"]; ?></td>
               <td><?php echo $res["awayteam"]; ?></td>
               <td><?php echo $res["competition"]; ?></td>
               <td><?php echo $res["date"]; ?></td>
               <td><?php echo $res["time"]; ?></td>
              <td><?php echo $res["channelid"]; ?></td>
              <td><?php echo $res["name"]; ?></td>
            </tr>

My issue is that the match details are displayed twice as there are two channels listed as showing the same match (see image) 我的问题是,比赛详细信息显示两次,因为列出了两个显示相同比赛的频道(参见图片)

incorrectoutput 错误的输出

my desired output is to have the details for each match to be shown once, and the names of multiple channels showing the matches to be displayed in the channel name column (no multiple rows) 我想要的输出是让每个匹配项的详细信息显示一次,并且显示匹配项的多个通道的名称将显示在通道名称列中(没有多行)

I tried using GROUP_CONCAT, but didn't have success, I tried GROUP_CONCAT as I know it is not recommended to have multiple values per field in MYSQL. 我尝试使用GROUP_CONCAT,但没有成功,我尝试了GROUP_CONCAT,因为我知道在MYSQL中建议不要在每个字段中使用多个值。

Many Thanks to anyone who can provide assistance or guidance. 非常感谢任何可以提供帮助或指导的人。

在HOME TEAM,AWAY TEAM和Competition上添加group_by以及频道的GROUP_CONCAT应该可以!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM