Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

'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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
652 views
Welcome To Ask or Share your Answers For Others

1 Answer

JOIN t2 ON t1.wid = t1.wid

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

EDIT

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;

NEXT EDIT

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;

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...