我的 sql 代码错误在哪里?

where is the fault in my sql code?(我的 sql 代码错误在哪里?)
本文介绍了我的 sql 代码错误在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

'SELECT * FROM t1
          JOIN t2 ON t1.wid = t2.wid
          WHERE t2.wid IS NULL
          LIMIT ' . $number;

这段代码没有任何返回给我你能帮我为什么我不取回值吗?

This code nothing returns to me could you help why i do not take values back??

推荐答案

JOIN t2 ON t1.wid = t1.wid

你是那个意思吗?或者你的意思是t1.wid = t2.wid?在这种情况下,您需要左连接.

did you mean that? or do you really mean t1.wid = t2.wid? in which case you'd want a left join.

编辑

好的,你修好了.除非 t2 中的行的 wid 与 t1 中具有相同 wid 的行匹配,否则不会显示任何结果.

Okay, so you fixed it. That won't show up any results unless there are rows in t2 that have a wid that matches a row in t1 with the same wid.

如果你想要结果,把它改成这样:

If you want results, change it to this:

'SELECT * FROM t1
          LEFT JOIN t2 ON t1.wid = t2.wid
          WHERE t2.wid IS NULL
          LIMIT ' . $number;

下一次编辑

如果目标是使用 t1 中尚未在 t2 中的值来更新 t2,那么它将是这样的:

If the goal is to update t2 with values from t1 that aren't ALREADY in t2, then it would be something like this:

'INSERT INTO t2 
   SELECT t1.* FROM t1
     LEFT JOIN t2 
        ON t1.wid = t2.wid
     WHERE t2.wid IS NULL
     LIMIT ' . $number;

缺少的步骤只是只返回 t1 的结果,然后将它们插入到 t2 中.

The missing step was simply to return only t1's results, and then insert them into t2.

这篇关于我的 sql 代码错误在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)