• <i id='OhK1L'><tr id='OhK1L'><dt id='OhK1L'><q id='OhK1L'><span id='OhK1L'><b id='OhK1L'><form id='OhK1L'><ins id='OhK1L'></ins><ul id='OhK1L'></ul><sub id='OhK1L'></sub></form><legend id='OhK1L'></legend><bdo id='OhK1L'><pre id='OhK1L'><center id='OhK1L'></center></pre></bdo></b><th id='OhK1L'></th></span></q></dt></tr></i><div id='OhK1L'><tfoot id='OhK1L'></tfoot><dl id='OhK1L'><fieldset id='OhK1L'></fieldset></dl></div>
    • <bdo id='OhK1L'></bdo><ul id='OhK1L'></ul>

    <legend id='OhK1L'><style id='OhK1L'><dir id='OhK1L'><q id='OhK1L'></q></dir></style></legend>

  • <small id='OhK1L'></small><noframes id='OhK1L'>

    <tfoot id='OhK1L'></tfoot>

        如何在 MySQL 中使用外键进行查询?

        时间:2023-09-24

            <tbody id='WTHm3'></tbody>

                <legend id='WTHm3'><style id='WTHm3'><dir id='WTHm3'><q id='WTHm3'></q></dir></style></legend>
                <i id='WTHm3'><tr id='WTHm3'><dt id='WTHm3'><q id='WTHm3'><span id='WTHm3'><b id='WTHm3'><form id='WTHm3'><ins id='WTHm3'></ins><ul id='WTHm3'></ul><sub id='WTHm3'></sub></form><legend id='WTHm3'></legend><bdo id='WTHm3'><pre id='WTHm3'><center id='WTHm3'></center></pre></bdo></b><th id='WTHm3'></th></span></q></dt></tr></i><div id='WTHm3'><tfoot id='WTHm3'></tfoot><dl id='WTHm3'><fieldset id='WTHm3'></fieldset></dl></div>
                  <bdo id='WTHm3'></bdo><ul id='WTHm3'></ul>

                  <tfoot id='WTHm3'></tfoot>

                  <small id='WTHm3'></small><noframes id='WTHm3'>

                  本文介绍了如何在 MySQL 中使用外键进行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  现在我有一个包含两个表的小型数据库,看起来像这样:

                  Right now I have a small database with two tables that look something like this:

                      users table
                      ====================
                      id  name   status_id
                      1   Bobby  3
                      2   James  2
                  

                      statuses table
                      =============
                      id  value
                      1   Waiting
                      2   Approved
                      3   Other
                  

                  status_id 被设置为状态表中 id 的外键约束.我的查询看起来像这样:

                  status_id is setup as a foreign key constraint to id from the statuses table. My query looks something like this:

                  SELECT *
                  FROM `users`
                  WHERE `status_id` = 2";
                  

                  当我显示 $row['status_id'] 它输出 2 但我希望它显示为 Approved 代替,什么是实现这一目标的最佳方法是什么?

                  When I display $row['status_id'] it outputs 2 but I would like it to display as Approved instead, what is the best way to accomplish this?

                  推荐答案

                  SELECT u.*, s.*
                  FROM users u
                      inner join statuses s on u.status_id = s.id
                  WHERE u.status_id = 2
                  

                  这篇关于如何在 MySQL 中使用外键进行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 jQuery Ajax 删除 mySQL 表行 下一篇:如何从 MySQL 中获取整数作为 PHP 中的整数?

                  相关文章

                  最新文章

                  <tfoot id='DDDrP'></tfoot>

                  <small id='DDDrP'></small><noframes id='DDDrP'>

                  • <bdo id='DDDrP'></bdo><ul id='DDDrP'></ul>
                  1. <legend id='DDDrP'><style id='DDDrP'><dir id='DDDrP'><q id='DDDrP'></q></dir></style></legend>
                    1. <i id='DDDrP'><tr id='DDDrP'><dt id='DDDrP'><q id='DDDrP'><span id='DDDrP'><b id='DDDrP'><form id='DDDrP'><ins id='DDDrP'></ins><ul id='DDDrP'></ul><sub id='DDDrP'></sub></form><legend id='DDDrP'></legend><bdo id='DDDrP'><pre id='DDDrP'><center id='DDDrP'></center></pre></bdo></b><th id='DDDrP'></th></span></q></dt></tr></i><div id='DDDrP'><tfoot id='DDDrP'></tfoot><dl id='DDDrP'><fieldset id='DDDrP'></fieldset></dl></div>