如何在mysql中组合两个具有所有不同列名的查询

时间:2017-06-08 05:15:00

标签: php sql

这是搜索产品的查询。数据包含来自不同两个表的产品列表。

$where = " Jewellery_Title like '%$id%' or Jewellery_SKU like '%$id%' and Jewellery_Status='Active'";
// $where_s = implode(' and ', $where);
$sql = "select * from jewellery where (".$where."".$jewellery_name." ) $metal_where  order by rank asc";
$res1 = query($con,$sql);
$total1 = row($res1);

$where = " Ring_Title like '%$id%' or Ring_SKU like '%$id%' $ring_name
and Ring_Status='Active'";
$sql = "select * from rings where (".$where.")  $metal_where order by rank asc";
$res2 = query($con,$sql);
$total2 = row($res2);

1 个答案:

答案 0 :(得分:2)

如上所述,在mysql查询中使用别名并运行数组合并。

    $scope.et = {};
    $scope.et.getNumPadStyle = {
        "padding-left" : "25px"
    }

如果您想要加入查询,请使用此

$sql=select jewelleryname as name from jewellery
$sql1=select ringname as name from rings 
// more code
 $total = row($res1);
 $total1 = row($res2);
$C = array_merge($total , $total1);