Thread esskar in der SQL welt (27 answers)
Opened by esskar at 2006-09-26 10:47

pq
 2006-10-20 17:17
#34719 #34719
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
Code: (dl )
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
mysql> select * from a;
+------+------+
| a_id | name |
+------+------+
| 1 | foo |
| 2 | bar |
| 4 | baz |
+------+------+
3 rows in set (0.00 sec)

mysql> select * from b;
+------+--------------------+
| b_id | descr |
+------+--------------------+
| 2 | descr for bar |
| 3 | descr for whatever |
| 4 | descr for baz |
+------+--------------------+
3 rows in set (0.01 sec)

mysql> select * from a INNER JOIN b on a.a_id=b.b_id;
+------+------+------+---------------+
| a_id | name | b_id | descr |
+------+------+------+---------------+
| 2 | bar | 2 | descr for bar |
| 4 | baz | 4 | descr for baz |
+------+------+------+---------------+
2 rows in set (0.01 sec)

mysql> select * from a LEFT JOIN b on a.a_id=b.b_id;
+------+------+------+---------------+
| a_id | name | b_id | descr |
+------+------+------+---------------+
| 1 | foo | NULL | NULL |
| 2 | bar | 2 | descr for bar |
| 4 | baz | 4 | descr for baz |
+------+------+------+---------------+
3 rows in set (0.00 sec)

mysql> select * from a RIGHT JOIN b on a.a_id=b.b_id;
+------+------+------+--------------------+
| a_id | name | b_id | descr |
+------+------+------+--------------------+
| 2 | bar | 2 | descr for bar |
| NULL | NULL | 3 | descr for whatever |
| 4 | baz | 4 | descr for baz |
+------+------+------+--------------------+
3 rows in set (0.01 sec)
\n\n

<!--EDIT|pq|1161350595-->
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread esskar in der SQL welt