union而不是in子句

union而不是in子句

本文介绍了SQL union而不是in子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有桌子



I have table

CREATE TABLE supportContacts
	(
     id int auto_increment primary key,
     type varchar(20),
     details varchar(30),
      code_id int
    );

INSERT INTO supportContacts
(type, details,code_id)
VALUES
('Email0', '[email protected]',1033),
('Email1', '[email protected]',1031),
('Email2', '[email protected]',1033),
('Email3', '[email protected]',1031),
('Email5', '[email protected]',1032),
('Email6', '[email protected]',1032),
('Twitter4', '4@sqlfiddle',1033);




当我运行此查询时






when i ran this query

Select type from supportContacts where code_id=1033
union
(
  Select type from supportContacts where code_id
  not in (Select type from supportContacts where code_id=1033)
)



输出是

TYPE

Email0

Email2

Twitter4

Email1

Email3

电子邮件5

电子邮件6



我想用join替换这个查询我该怎么做。



谢谢


output is
TYPE
Email0
Email2
Twitter4
Email1
Email3
Email5
Email6

I want to replace this query with join's how can i do that.

Thanks

推荐答案


这篇关于SQL union而不是in子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 06:20