clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 921257 fiddles created (11948 in the last week).

CREATE TABLE invoice1 (InvoiceID INT, UserID INT); INSERT INTO invoice1 VALUES (1230,1), (1231,3), (1232,2), (1233,5), (1234,8), (1235,4), (1236,7), (1237,6), (1238,9), (1239,10); SELECT * FROM invoice1;
InvoiceID UserID
1230 1
1231 3
1232 2
1233 5
1234 8
1235 4
1236 7
1237 6
1238 9
1239 10
 hidden batch(es)


CREATE TABLE invoice2 (InvoiceID INT, UserID INT); INSERT INTO invoice2 VALUES (1230,10), (1231,9), (1232,8), (1233,7), (1234,6), (1235,5), (1236,1), (1237,2), (1238,3), (1239,4); SELECT * FROM invoice2;
InvoiceID UserID
1230 10
1231 9
1232 8
1233 7
1234 6
1235 5
1236 1
1237 2
1238 3
1239 4
 hidden batch(es)


SELECT InvoiceID, UserID, @num := @num + 1 rownumber FROM invoice1, (SELECT @num:=0) variable WHERE InvoiceID > 1234 ORDER BY UserId;
InvoiceID UserID rownumber
1235 4 1
1237 6 2
1236 7 3
1238 9 4
1239 10 5
 hidden batch(es)


SELECT InvoiceID, UserID, @num := @num + 1 rownumber FROM invoice2, (SELECT @num:=0) variable WHERE InvoiceID > 1234 ORDER BY UserId;
InvoiceID UserID rownumber
1236 1 1
1237 2 2
1238 3 3
1239 4 4
1235 5 5
 hidden batch(es)


SELECT t1.InvoiceID, t1.UserID, t2.InvoiceID, t2.UserID FROM ( SELECT InvoiceID, UserID, @num1 := @num1 + 1 rownumber FROM invoice1, (SELECT @num1 := 0) variable WHERE InvoiceID > 1234 ORDER BY UserId ) t1 JOIN ( SELECT InvoiceID, UserID, @num2 := @num2 + 1 rownumber FROM invoice2, (SELECT @num2 := 0) variable WHERE InvoiceID > 1234 ORDER BY UserId ) t2 USING (rownumber)
InvoiceID UserID InvoiceID UserID
1235 4 1236 1
1237 6 1237 2
1236 7 1238 3
1238 9 1239 4
1239 10 1235 5
 hidden batch(es)