我有这个查询,它正确显示结果。我没有使用 join,但它似乎仍然返回正确的值,这怎么可能?
SELECT connections.id,
connections.word_id,
connections.order_id,
connections.top,
connections.deleted,
(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(connections.modified)) AS modified_ago,
words_en.word,
(CASE WHEN words_en.user_id = 1 THEN "You" ELSE words_en.user_id END) AS created_by
FROM connections, words_en
WHERE connections.word_id = words_en.id AND connections.user_id = 1
IN (SELECT COUNT(*) connections WHERE /* Result of previous select connections.word_id */ AND connections.user_id != 1)
ORDER BY connections.order_id
这样做是否足够:
connections.word_id = words_en.id
加入?我还想为此添加子查询。那是什么语法?
子查询应该计算conenctions.word_id
出现在连接表中的次数,其中connections.user_id != 1
ergo 其他用户使用这个词的次数。
- 我还需要另一个可以让我
users.name_surname
获得words_en.user_id
.