mySQL查询仅检索左表中的记录

时间:2017-05-30 11:31:07

标签: mysql database join

如何编写mysql查询以使左表中的记录 Left Join为我提供了T1表中的所有记录,而mySQL中没有MINUS

only left

修改
不希望使用子查询

2 个答案:

答案 0 :(得分:4)

使用<body> <h2>Traversering og elementskapelse</h2> <div> <label>Antall div'er å generere: <input id="nmbrSquare" type="number" value="5"> </label> <input id="addSquareBtn" type="button" value="Generér"> </div> <div id="boxes"></div> <script> function generateDivs(amount) { container.empty(); for (var i = 0; i < amount; i++) { var div = $('<div>'); div.addClass('box'); container.append(div); } } var container = $('#boxes'); $("#addSquareBtn").click(function() { var nmbrSquare = $("#nmbrSquare").val(); generateDivs(nmbrSquare) }); generateDivs(1); $(function() { $(document).on('click','#boxes',function(){ $(event.target).css('background-color', 'plum'); $(event.target).prev().css('background-color', 'plum'); $(event.target).next().css('background-color', 'plum'); }); }); </script> </body>

not exists

如果需要更多列比较,可以扩展逻辑:

select l.*
from `left` l
where not exists (select 1 from `right` r where r.id = l.id);

答案 1 :(得分:1)

您正在寻找左排除连接

  SELECT  A.*
  FROM Table_A A
  LEFT JOIN Table_B B
  ON A.Key = B.Key
  WHERE B.Key IS NULL

有关SQL连接的文章,请参阅此文章 https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins