这是我的查询:
SELECT *
FROM comments
INNER JOIN posts ON 'comments.postPostId' = 'posts.post_id';
所有评论:
blog=# select * from comments;
comment_id | uid | content | postPostId
--------------------------------------+--------------------------------------+-------------------------+--------------------------------------
49104d66-aebf-48f5-b816-46d9def8edc2 | 5ef3d422-8b98-4509-a752-5ac8d1aee40d | oh man this game is lit | 1c756322-0042-4d8e-bab8-e04a9ceb981e
(1 row)
所有帖子:
blog=# select * from posts;
post_id | uid | title | sub_title | content | userUserId
--------------------------------------+--------------------------------------+-------+----------------+---------+--------------------------------------
1c756322-0042-4d8e-bab8-e04a9ceb981e | 2e83d249-7c7c-43c0-8e3d-854ddac7c1b8 | bf1 | love this game | bla bla | 6cc903a7-11bf-43a4-a75a-3e1456404525
(1 row)
结果:
blog=# SELECT * FROM comments INNER JOIN posts ON 'comments.postPostId' = 'posts.post_id';
comment_id | uid | content | postPostId | post_id | uid | title | sub_title | content | userUserId
------------+-----+---------+------------+---------+-----+-------+-----------+---------+------------
(0 rows)
为什么它是一个空集?从技术上来说我不应该退回一排吗?
通过在'
中包装列名,您正在比较这些文字,它们总是产生false。稍微放下'
:
SELECT * FROM comments INNER JOIN posts ON comments.postPostId = posts.post_id;