【问题标题】:mysql join query not using subselect()mysql 连接查询不使用 subselect()
【发布时间】:2016-01-07 02:53:01
【问题描述】:

在我的应用程序中,我得到了一个用户名。 表格设计如下:

用户表:

id|用户名

端口表:

user_id|端口

编写查询的最佳方法是使用他的 id 查找属于用户的端口(用户只能有一个与他的 id 关联的端口)?我不想为此写查询。

【问题讨论】:

  • 你能贴出你目前尝试过的SQL吗?

标签: mysql join


【解决方案1】:

只需连接两个表:

select port from users inner join ports
on users.id = port.user_id 
Where users.id = <userid>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 2011-07-20
    • 1970-01-01
    • 2021-12-20
    • 2015-09-26
    相关资源
    最近更新 更多