gpt4 book ai didi

mysql - 使用多个表的 phpmyadmin 查询

转载 作者:行者123 更新时间:2023-11-29 19:16:14 33 4
gpt4 key购买 nike

我会简单地说我的数据库中有 2 个表1. 邮寄2.用户

Post 表中的列是帖子ID用户ID帖子标题发布内容

那么用户表中的列是用户 ID - 连接到 Post.User ID用户全名

那么我现在要做的是选择Juan Cruz(用户.用户全名)发布的帖子。请帮忙,我在任何地方都找不到这些问题。

PS 抱歉我的英语不好。

编辑:我将使用它作为我的 php/html 项目的搜索模块。所以我需要知道 Juan Cruz 发布的帖子以及 Juan Cruz 的用户 ID。再次感谢

最佳答案

希望这可能有所帮助:

SELECT
p.post_id, p.user_id, p.post_title, p.post_content,
u.user_fullname
// column name from two or more tables
// eg: table_name.column_name
// use p and u, because we already give temporary name for table post and user
FROM
post p // table 1: post refer as p (SQL aliases)
JOIN // combine 2 column from two or more tables
user u // table 2: user refer as u (SQL aliases)
ON
p.user_id = u.user_id // key for joining the table, the ID should be the same

或者您可以使用以下不带别名的代码:

SELECT
post.post_id, post.user_id, post.post_title, post.post_content,
user.user_fullname
FROM
post
JOIN
user
ON
post.user_id = user.user_id

引用:SQL JOIN

关于mysql - 使用多个表的 phpmyadmin 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42685777/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com