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 > Relationship between two tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-31-10, 01:40
linux1880 linux1880 is offline
Registered User
 
Join Date: Jul 2010
Posts: 39
Relationship between two tables

Hi all I am new to database and this db forums,

Wondering, If there are two tables in a database with primary key are they in relationship without needing to add foreign keys ?

I did
PHP Code:
select col1col2 from table1,table2 
it fetch two columns from two different tables. There was no fk.

Is that possible without foreign key ?
Reply With Quote
  #2 (permalink)  
Old 07-31-10, 03:18
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
It is possible (that is called a Cartesian Join), but it is extremely unlikely in the real world.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 07-31-10, 04:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by linux1880 View Post
Wondering, If there are two tables in a database with primary key are they in relationship without needing to add foreign keys ?
they can be, if the database designer did a less than comprehensive job

is it possible to join them? sure, you can join two tables in a query on any columns you want, or, as pat has said, on no columns at all

you can also UNION them --
Code:
SELECT col1
  FROM table1
UNION
SELECT col2
  FROM table2
if you could be a bit more specific than the obfuscatory "col1,col2" and "table1,table2" then maybe we could offer more than just general comments
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 08-19-10, 18:39
rein01 rein01 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
yes it is possible....but could you be more specific on your example? What is the logical relationship between the two tables? Usually you can join them if one of the attributes in both tables have the same value, in this case this attribute can act as your foreign key even though it's not declared as one. But if you don't have attributes in both tables that does not hold the same value, you can still perform a table wide merge.
Reply With Quote
Reply

Tags
mysql

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