-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathguestbooks.sql
55 lines (46 loc) · 1.21 KB
/
guestbooks.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
CREATE TABLE guestbooks
(
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(100),
title VARCHAR(200),
content TEXT,
PRIMARY KEY (id)
) ENGINE = InnoDB;
SELECT *
FROM customers;
INSERT INTO guestbooks(email, title, content)
VALUES ('[email protected]', 'Hello', 'Hello'),
('[email protected]', 'Hello', 'Hello'),
('[email protected]', 'Hello', 'Hello'),
('[email protected]', 'Hello', 'Hello'),
('[email protected]', 'Hello', 'Hello'),
('[email protected]', 'Hello', 'Hello');
SELECT *
FROM guestbooks;
SELECT email
FROM customers
UNION
SELECT email
FROM guestbooks;
SELECT email
FROM customers
UNION ALL
SELECT email
FROM guestbooks;
SELECT emails.email, COUNT(emails.email)
FROM (SELECT email
FROM customers
UNION ALL
SELECT email
FROM guestbooks) as emails
GROUP BY emails.email;
SELECT DISTINCT email
FROM customers
WHERE email IN (SELECT DISTINCT email FROM guestbooks);
SELECT DISTINCT customers.email
FROM customers
INNER JOIN guestbooks ON (guestbooks.email = customers.email);
SELECT DISTINCT customers.email, guestbooks.email
FROM customers
LEFT JOIN guestbooks ON (customers.email = guestbooks.email)
WHERE guestbooks.email IS NULL;