Php 查看查询,具有相同字段';数据库中的姓名

Php 查看查询,具有相同字段';数据库中的姓名,php,sql,algorithm,select,Php,Sql,Algorithm,Select,我有这张桌子 table a +-------+---------+ |userid |Pid | +-------+---------+ | 1 |P1 | | 1 |p2 | | 2 |p3 | | 2 |P4 | +-------+---------| table b +-------+---------+ |userid |Pid | +-------+---------+ | 1

我有这张桌子

table a
+-------+---------+
|userid |Pid      |
+-------+---------+
|   1   |P1       |
|   1   |p2       |
|   2   |p3       |
|   2   |P4       |
+-------+---------|

table b
+-------+---------+
|userid |Pid      |
+-------+---------+
|   1   |P3       |
|   1   |p4       |
|   2   |p1       |
|   2   |P2       |
+-------+---------|
您知道如何使用表A中的其他用户,其中表B中的用户的pid等于表A中的其他用户pid,表B中的其他用户pid等于表A中的用户pid吗

select other user where
user table B.pid = other user table A.pid
and
other user B.pid= user table A.pid

我不确定我是否理解你的问题,但请尝试以下方式:

SELECT b.userid
FROM   a
       INNER JOIN b
               ON a.pid = b.pid
WHERE  a.userid=someId

这是非常基本的SQL,也许你应该阅读一些教程。

我添加了“where user_id!=“1”,但是SQL说用户id是模糊的,如果列是模糊的,有没有办法添加“where”子句而不更改表???
where a.user_id=1
使用表别名