试图弄清楚是否可以创建一个查询来连接表,表一小于表二,表二有多个与表一条目匹配的引用,查询将输出一个连接,其中表一的长度被保留,但你只是添加更多列。不确定这是否有意义,所以这是我所追求的一个例子
Table One Table two
+-----------------------------+ +-----------------------------+
| id | english | definition | | id | word_id | sentence |
+-----------------------------+ +-----------------------------+
|1 | A1 | blah | |1 | 1 | blahblah1 |
|2 | B4 | blah2 | |2 | 1 | blahblah2 |
+-----------------------------+ |3 | 1 | blahblah3 |
|4 | 2 | blahblah4 |
|5 | 2 | blahblah5 |
+-----------------------------+
********* 查询应返回类似 ***************** 的内容
+----------------------------------------------------------------+
| id | english | definition | sentence | sentence2 | sentence3 |
+----------------------------------------------------------------+
|1 | A1 | blah | blahblah1| blahblah2| blahblah3 |
|2 | B4 | blah2 | blahblah4| blahblah5| |
+----------------------------------------------------------------+
我当前的查询看起来像这样并导致:
$query = "SELECT * FROM T1 INNER JOIN T2 ON T1.id = T2.word_id";
导致:
+----------------------------------------+
| id | english | definition | sentence |
+----------------------------------------+
|1 | A1 | blah | blahblah1|
|1 | A1 | blah | blahblah2|
|1 | A1 | blah | blahblah3|
|2 | B4 | blah2 | blahblah4|
|2 | B4 | blah2 | blahblah5|
+----------------------------------------+
我正在使用 PHP 和 MySql。
更新!!
保留我的原始查询并使用 PHP 操作结果也获得了良好的性能。如果您需要我发布我的代码,请告诉我。