如何在 JOIN MySQL 查询/操作中保留原始 ID? [英] How to preserve original ID in JOIN MySQL query/ operation?

查看:41
本文介绍了如何在 JOIN MySQL 查询/操作中保留原始 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.

SELECT DISTINCT * FROM '.PRFX.'sell sell JOIN '.PRFX.'followed follow ON follow.id_ = sell.id WHERE draft = "0" AND follow.uid = "'.$u.'" ORDER BY follow.id DESC '.$sql_limit

那个订单表,但它弄乱了原来的'.PRFX.'sell ID(与follow.id交换)

that orders table, but it messes with the original '.PRFX.'sell ID (exchanging it with the follow.id)

如何恢复原状?

示例弄乱了我的原始 ID(来自销售表),我必须保留它.怎么做(还在等答案)?

Examples mess my original ID (from sell table) and i MUST preserve it. How to do it (Still waiting for an answer)?

推荐答案

明确列出您的列并使用列别名:

List your columns explicitly and use column aliases:

SELECT DISTINCT sell.*, follow.id as followid
FROM '.PRFX.'sell sell JOIN '.PRFX.'followed follow
      ON follow.id_ = sell.id
WHERE draft = "0" AND follow.uid = "'.$u.'"
ORDER BY follow.id DESC '.$sql_limit;

您可以根据需要添加更多列.只需确保它们具有不同的名称(您可以使用 as 指定).

You can add more columns in as you like. Just be sure they have different names (which you can assign using as).

这篇关于如何在 JOIN MySQL 查询/操作中保留原始 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆