我有两张桌子:
发布
附件
我想搜索那些文件名包含".txt".的附件的帖子。
我已经使用了所有类型的连接,但仍然无法工作。
SELECT posts.*, filename FROM posts LEFT JOIN attachments ON posts.id = attachments.post_id WHERE filename LIKE '%.txt%'上面的SQL不返回任何行。当我使用右联接时,它返回行,但是只有文件名列有一个值,posts表中的列都包含NULL。
有什么帮助吗?
更新
对不起,这一定是MySQL的问题。我重新启动了MySQL服务器,现在查询工作起来了。对不起,谢谢你的帮助。
发布于 2013-04-13 09:24:05
使用INNER JOIN
SELECT
posts.*,
filename
FROM posts
INNER JOIN attachments
ON posts.id = attachments.post_id
WHERE attachments.filename LIKE '%.txt%'https://stackoverflow.com/questions/15986197
复制相似问题