简体   繁体   English

我的SQL查询通过mm连接多个表

[英]My SQL query for join multiple tables via mm

im looking for a SQL statement for the structue below. 我正在寻找以下结构的SQL语句。 I want select all uid's and texts of the tables, which got a relation to the table declined : 我想选择表的所有uid和文本,这些与表的关系被拒绝

  • partsofspeech 词性
  • verbs_tempus verbs_tempus
  • words_case words_case
  • words_language words_language
  • words_relation words_relation

Each table has the fields uid and text . 每个表都有uidtext字段。 Each table got a mm table to save any relation. 每个表都有一个mm表来保存任何关系。 The local value belongs to the uid of related table itself. 本地值属于相关表本身的uid Foreign represents the uid of decline . 外国代表衰落流体

I want do this with 1 SQL query. 我想用1个SQL查询来做到这一点。 I think it should be possible with joins but im new with these. 我认为加入应该有可能,但这些是新的。 Here is a 'lil graphic: 这是一个'lil图形: 在此处输入图片说明

Here is my query: 这是我的查询:

SELECT partsofspeech.uid, partsofspeech.text from declined
LEFT JOIN partsofspeech_mm
ON partsofspeech_mm.foreign = declined.uid
LEFT JOIN partsofspeech
ON partsofspeech_mm.local = partsofspeech.uid

fiddle: 小提琴:

sql fiddle sql小提琴

Does any1 has a clue to handle this recursive probably? 是否有任何线索可能会处理此递归?

Here's the first table partsofspeech done for you 这是为您完成的首个表partsofspeech

SELECT T1.uid,T1.text,T2.local,T2.foreign,T3.uid,T3.text
  FROM partsofspeech T1
  INNER JOIN partsofspeech_nm T2 ON (T1.uid = T2.local)
  INNER JOIN declined T3 ON (T2.foreign = T3.uid)

you can do the rest for the other tables and UNION them together. 你可以做其他表,其余UNION在一起。

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

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