If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > null foreign keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-29-04, 15:14
midget midget is offline
Registered User
 
Join Date: Mar 2003
Location: SJ, Costa Rica
Posts: 48
null foreign keys

HI everybody...
I have the following tables:
Code:
CREATE TABLE player(
   id_player varchar(10),
   first_name varchar(20),
   last_name varchar(50),
   id_team varchar(10));

CREATE TABLE team(
   id_team varchar(10),
   team_name varchar(50));
I have the following situation:
* id_team is a foreign key in the "player" table.
* There are players that doesn't have a team.

if I make the following select:
Code:
  SELECT P.first_name,P.last_name,T.team_name FROM
                 player P, team T WHERE
                           P.id_team=T.id_team
and the player does not have a valid team, I don't receive any recor in return despite the player exists.
Is there a way to retreive the record despite my foreign key(id_team) is null?
thanks in advance for any help.
regards,
-eduardo s.m.
Reply With Quote
  #2 (permalink)  
Old 01-29-04, 16:44
midget midget is offline
Registered User
 
Join Date: Mar 2003
Location: SJ, Costa Rica
Posts: 48
Talking

I found the solution myself:
this resolves the problem:

Code:
SELECT   P.first_name,P.last_name,T.team_name FROM
                player P left outer join team T on
                P.id_team=T.id_team WHERE
                id_player=1
greetings,
-eduardo s.m.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On