Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    39

    Unanswered: 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 ?

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •