mysqli列出电子邮件,如果另一个表没有它

时间:2016-02-24 15:47:05

标签: mysql sql mysqli

有没有办法只使用SQL代码返回mail@site6.com, mail@site4.com and mail@site5.com

列出Table_2中存在但Table_1中不存在的电子邮件。我可以使用PHP来完成它,但必须通过仅使用SQL来实现。我对MySQL子查询不太满意。

Table_1
id | email
------------
1  | mail@site1.com
2  | mail@site2.com
3  | mail@site3.com

Table_2
id | email
------------
1 | mail@site1.com
2 | mail@site3.com
3 | mail@site6.com
4 | mail@site4.com
5 | mail@site5.com

2 个答案:

答案 0 :(得分:1)

您可以使用NOT IN;

SELECT email 
FROM Table_2
WHERE email NOT IN (SELECT email FROM Table_1);

...或LEFT JOIN ...

SELECT t2.email
FROM Table_2 t2
LEFT JOIN Table_1 t1
  ON t1.email = t2.email
WHERE t1.id IS NULL

答案 1 :(得分:0)

var ReactQuill = require('react-quill');
var CustomQuill = React.createClass({
  mixins: [ ReactQuill.Mixin ],

  componentDidMount: function() {
    var editor = this.createEditor(
      this.getEditorElement(),
      this.getEditorConfig()
    );
    this.setState({ editor:editor });
  },

  componentWillReceiveProps: function(nextProps) {
    if ('value' in nextProps && nextProps.value !== this.props.value) {
      this.setEditorContents(this.state.editor, nextProps.value);
    }
  },

  /* ... */
});