如何将这两个查询合并为一个?
第一个查询获取特定类别的所有posts_id;post_category 表中的 postId 等于 post 表中的 id
select distinct postId
from post_category
where categoryId='125' or categoryId='3'
然后我想加入他们,这样它就会从 post 表中的 post_category 中选择所有 postId
SELECT * FROM post <<query one join>> AND approve=1"
邮政
+--------------+-----------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-----------------------+------+-----+---------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| autor | varchar(40) | NO | MUL | | |
| date | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| short_story | text | NO | MUL | NULL | |
| full_story | text | NO | MUL | NULL | |
| xfields | text | NO | | NULL | |
| title | varchar(255) | NO | MUL | | |
| descr | varchar(200) | NO | MUL | | |
| keywords | text | NO | | NULL | |
| category | varchar(200) | NO | MUL | 0 | |
| alt_name | varchar(200) | NO | MUL | | |
| comm_num | mediumint(8) unsigned | NO | MUL | 0 | |
| allow_comm | tinyint(1) | NO | | 1 | |
| allow_main | tinyint(1) unsigned | NO | MUL | 1 | |
| approve | tinyint(1) | NO | MUL | 0 | |
| fixed | tinyint(1) | NO | | 0 | |
| allow_br | tinyint(1) | NO | | 1 | |
| symbol | varchar(3) | NO | MUL | | |
| tags | varchar(255) | NO | MUL | | |
| metatitle | varchar(255) | NO | | | |
| FileTempUUID | varchar(11) | YES | | NULL | |
+--------------+-----------------------+------+-----+---------------------+----------------+
post_category;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| cid | bigint(11) | NO | PRI | NULL | auto_increment |
| postId | int(11) | NO | | NULL | |
| categoryId | smallint(6) | NO | | NULL | |
+------------+-------------+------+-----+---------+----------------+