最有效的方法是根据外键删除条目

时间:2016-12-13 21:28:03

标签: mysql sql

我可以执行以下连接以获取History表中具有Platform =“Vudu”的所有项目。

SELECT * FROM main_history History INNER JOIN main_iteminstance Instance
ON History.instance_id=Instance.id
WHERE platform_type_id='vudu'

但是,我找不到一种简单的方法来删除所有这些项目。例如,要执行以下操作:

DELETE from main_history h join main_iteminstance i on h.instance_id=i.id
WHERE platform_type_id='vudu'

如何在单个查询中基于ForeignKey在Mysql中删除?

1 个答案:

答案 0 :(得分:2)

你非常非常接近:

function iterateAddresses () {

  var time = 500;

  $.each( addresses_google, function( index, value ) {
    var service = new google.maps.DistanceMatrixService();

    service.getDistanceMatrix(
      {
        origins: [origin],
        destinations: value,
        travelMode: 'DRIVING'
      },
      callback
    );

    function callback(response, status) {
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
      for (var i = 0; i < origins.length; i++) {
        var results = response.rows[i].elements;
        for (var j = 0; j < results.length; j++) {
          var element = results[j];
          if(element.status == "NOT_FOUND"){
            var distance = 0;
          } else {
            var distance = element.distance.value;
          }
          if(distance > radius){
            // Store postids in array
            postids_to_hide.push(
              addresses_postids[index][j]
            );
            // Hide elements where postid is in the postids_to_hide arrays
            $.each( postids_to_hide, function( index, value ) {
              $(".main_short_post_div").filter(function(){
                return $(this).attr('data-post-id') === value;
              }).hide();
            });
          } // end if d < r
        } // end for j
      } // end for i
    } // end callback function
  }); // end each addresses_google

}; // end iterateAddresses

iterateAddresses();

MySQL只需要知道要删除的表(或多个表)。