mySQL JOIN 将文本添加到变量

标签 mysql variables join

这是一个 mySQL 查询。麻烦的是我们需要给 theme.ref 添加前缀和后缀才能使其匹配

SELECT * FROM content LEFT JOIN theme ON content.ID LIKE theme.ref 
WHERE content.status = 1 AND content.parent = 11 AND content.type = 'team' 
ORDER BY content.position ASC

在显示 content.ID LIKE theme.ref 的第一个链接上,是否可以在 theme.ref 之前添加文本“ID”,在其之后添加“,”。这可以做到吗?如果可以的话如何做到。

例如。 'ID'.theme.reg.',' 显然这是行不通的。

最佳答案

content.ID LIKE concat('ID',theme.ref,',') (如果 theme.ref 不包含通配符,则相当于 content.ID = concat('ID',theme.ref,','))

但是查询效率会很低。也许,它应该被重写或者整个数据模型被改变。

关于mySQL JOIN 将文本添加到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19466771/

相关文章:

php - F3 : Is there a way to convert an array into an object with additional fields?

php - PDO rowCount 仅返回 1

mysql - 参数 2 中的 JSON 文本无效 - MySQL 5.7.8 中的 json_contains

c - file->d_name 到 C 中的变量中

variables - 在 Node.js 中,为什么我应该更喜欢键值存储而不是应用程序变量?

postgresql - postgresql 中的 JOIN 非常慢

mysql - 加入 3 个表并选择计数

php - mysql - 在 sql 中选择 UNTIL

c++ - 编写我自己的 C++ 编译器 .. 卡在变量上

MySQL 在连接时丢失行