gpt4 book ai didi

php - 如何从具有其他表条件的表中进行选择

转载 作者:行者123 更新时间:2023-11-29 08:05:34 25 4
gpt4 key购买 nike

我有这个 mysql 设置:

*words* table
+----+-----------+
| id | word |
+----+-----------+
| 1 | curse1 |
| 2 | curse2 |
| 3 | niceWord1 |

*Category* table
+----+-----------+
| id | name |
+----+-----------+
| 1 | niceWords |
| 2 | badWords |

*link* table
+----+--------+-------+
| id | wordID | catID |
+----+-----------+----+
| 1 | 1 | 2 |
| 2 | 2 | 2 |
| 3 | 3 | 1 |

我想做一个 MySQL SELECT,我说我想使用链接表选择所有坏词
所以我会得到类似这样的输出:

+----------+------------+---------------+
| words.id | words.word | Category.name |
+----------+------------+---------------+
| 1 | curse1 | badWords |
| 2 | curse2 | badWords |

我想我需要使用某种 JOIN,我不太擅长 SQL。

Pastebin 具有相同的内容:http://pastebin.com/ML684RRA

最佳答案

select words.id, words.word, Category.name
from words
join link on link.wordid = words.id
join category on category.id = link.catid
where category.name = 'badWords'

关于php - 如何从具有其他表条件的表中进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com