加入2个结果表

时间:2017-02-21 04:04:34

标签: mysql

我有两个查询来从我的数据库中获取数据。

SET @row_num0 = 0;
SELECT @row_num0 := @row_num0 + 1 AS RIdx1,
       U.name
FROM users U


SET @row_num1= 0;
SELECT @row_num1 := @row_num1 + 1 AS RIdx2,
       C.color
FROM colors C

我想将第一个查询RIdx1的结果加入第二个查询RIdx2
说明....我想从color table为每个用户user table获取一种独特的颜色
我已经厌倦了使用nested SELECT而我无法在SELECT下使用SET @
无论如何我可以用来为每个用户获取颜色吗?

编辑::::
嵌套的SELECT Query ....

SELECT *
FROM
(
    SET @row_num0 = 0;
    SELECT @row_num0 := @row_num0 + 1 AS RIdx1,
           U.name
    FROM users U
) DATA0
LEFT JOIN
(
    SET @row_num1= 0;
    SELECT @row_num1 := @row_num1 + 1 AS RIdx2,
           C.color
    FROM colors C
) DATA1
ON DATA0.RIdx1 = DATA1.RIdx2

发生SQL错误。我无法加入这两个选择查询。请帮帮....

1 个答案:

答案 0 :(得分:0)

请考虑以下事项:

function UpdateOrderStatus(){

var domainName = "http://xxxxx.xxxxx.com/xxxxxxxx.xxxx.xxxxxxxxxxx/1_1/MainService.svc/webapi/UpdateOrderStatus";
var orderData = {
    "wsCodeCrypt" : "xxxxxx",
    "caUid" : "xxxxxx",
    "caPwd" : "xxxxxxxxxx",
    "slsDoc" : "SO",
    "slsRef" : "00001",
    "status" : "pending"
};

$.ajax({
    url: domainName, 
    method: "POST",
    data: orderData,
    cache: false,
    dataType: "xml",
    success: function(xml) {
        console.log(xml);
    },
    error: function( xhr, status, errorThrown ) {
        console.log( "Error: " + errorThrown );
        console.log( "Status: " + status );
    }
});