遇到这个问题,我不知道如何从多个表中提取数据。我试图使用INNER JOIN和UNION。 以下是我到目前为止的情况:
select `name_ganre` from `teleprogram`.`ganres`
where `idganre`=any(select `idganre` from `teleprogram`.`ganre-transfer`
where `idtransfer`=any(select `idtransfer` from `teleprogram`.`broadcasting`));
select `name_channel` from `teleprogram`.`channel`
where `idchannel`= any(select `idchannel` from `teleprogram`.`broadcasting`);
我需要引入一个频道的列名。这个类型的另一个名字。
broadcasting
rows: idtransfer, idchannel
transfer
rows: idtransfer, name_transfer
ganre-transfer
rows: idganre, idtransfer
ganre
rows: idganre, name_ganre
channels
rows: idchannel, name_channel
我正在尝试通过广播获取数据。可以简化吗? 查询后:name_channel,name_ganre
谢谢!
答案 0 :(得分:1)
您需要的查询是:
select c.name_channel, g.name_ganre
from channels c
inner join broadcasting b on b.idchannel = c.idchannel
inner join ganre-transfer gt on gt.idtransfer = b.idtransfer
inner join ganre g on g.idganre = gt.idganre
您可以看到INNER JOIN
的工作原理HERE!