Click here to Skip to main content
15,915,093 members
Home / Discussions / Database
   

Database

 
GeneralRe: Sql database modification Pin
Colin Angus Mackay20-May-05 0:42
Colin Angus Mackay20-May-05 0:42 
GeneralRe: Sql database modification Pin
webhay20-May-05 0:48
webhay20-May-05 0:48 
GeneralRe: Sql database modification Pin
GreggS20-May-05 6:08
GreggS20-May-05 6:08 
GeneralHELP!!! using distinct keyword causes error 0x80040E21 Pin
oyinbogo19-May-05 7:21
oyinbogo19-May-05 7:21 
Generalhelp in undertsnading the joins Pin
satishrg19-May-05 5:31
satishrg19-May-05 5:31 
GeneralRe: help in undertsnading the joins Pin
Colin Angus Mackay19-May-05 6:39
Colin Angus Mackay19-May-05 6:39 
GeneralRe: help in undertsnading the joins Pin
satishrg19-May-05 7:58
satishrg19-May-05 7:58 
GeneralRe: help in undertsnading the joins Pin
Colin Angus Mackay19-May-05 12:34
Colin Angus Mackay19-May-05 12:34 
A self join is just when you join a table onto itself. There is no special types of join.

Consider a table with a primary key, PK, and a foreign key, FK, and the foreign key refers to the primary key of a different row in the same table.

For instance:

PK FK
-------
1  3
2  3
3  7
4  7
5  8
6  3
7  null
8  null
Now, do a join onto itself like this:
SELECT * FROM table AS t1 INNER JOIN table AS t2 ON t1.fk = t2.pk
t1.PK t1.FK t2.PK t2.FK
------------------------
1     3     3     7
2     3     3     7
3     7     7     null
4     7     7     null
5     8     8     null
6     3     3     7


Remember that t1 and t2 are actually the same table, you need the aliases so you can treat the table as if it were actually two separate tables. Once you have the aliased, you can do any type of join you like that you could on two separate tables. Also, thinking about it as being two separate tables, that happen to both hold exactly the same data makes it easier to comprehend.

Does this help?



My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More


Questionproblem with update a row? Pin
Sasuko19-May-05 5:10
Sasuko19-May-05 5:10 
AnswerRe: problem with update a row? Pin
Colin Angus Mackay19-May-05 5:31
Colin Angus Mackay19-May-05 5:31 
GeneralRe: problem with update a row? Pin
Sasuko19-May-05 11:41
Sasuko19-May-05 11:41 
AnswerRe: problem with update a row? Pin
Luis Alonso Ramos19-May-05 14:09
Luis Alonso Ramos19-May-05 14:09 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 2:57
Sasuko20-May-05 2:57 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 4:19
Sasuko20-May-05 4:19 
GeneralRe: problem with update a row? Pin
Luis Alonso Ramos20-May-05 4:58
Luis Alonso Ramos20-May-05 4:58 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 5:00
Sasuko20-May-05 5:00 
GeneralRe: problem with update a row? Pin
Luis Alonso Ramos20-May-05 5:11
Luis Alonso Ramos20-May-05 5:11 
GeneralRe: problem with update a row? Pin
Sasuko20-May-05 5:21
Sasuko20-May-05 5:21 
GeneralRe: problem with update a row? Pin
Blue_Boy24-May-05 4:01
Blue_Boy24-May-05 4:01 
Generalpicture inserting.please help me! Pin
rohollahabadan19-May-05 2:20
rohollahabadan19-May-05 2:20 
GeneralRe: picture inserting.please help me! Pin
NewSilence21-May-05 12:11
NewSilence21-May-05 12:11 
GeneralRe: picture inserting.please help me! Pin
rohollahabadan22-May-05 21:23
rohollahabadan22-May-05 21:23 
Generalplease help me .please please.... Pin
rohollahabadan19-May-05 2:12
rohollahabadan19-May-05 2:12 
GeneralRe: please help me .please please.... Pin
RChin19-May-05 3:48
RChin19-May-05 3:48 
GeneralThe stored procedure .... Pin
rohollahabadan20-May-05 23:19
rohollahabadan20-May-05 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.