SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member Aber_Al's Avatar
    Join Date
    Dec 2004
    Location
    Wales
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inner-Join vs Foreign Key

    Hi,

    OK so i'll throw my hands up and admit- i'm somewhat a newbie in the practicalities of mysql (relationships and normal form, on the other hand, are no probs).

    I've been trying to design a database where a property table holds an entry for a property that is for sale and there is one field "user-id" that I want to link to the user table so that when they select the property from the list of displayed properties I can query both tables in order to get info regarding the seller and the property.

    It's a 1:many relationship (user: property) and I was wondering this...

    I was going to have the "user-id" in the property table as a FK relating to the "user" table. However I've also seen that "..JOIN" statements exist and I was wondering which is the best method to use? If I use the FK do i still need to create the query with a 'join' syntax?

    Cheers guys,

    Al.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    yes

    foreign keys are used to ensure data integrity (when they are supported)

    to retrieve data from two tables, you must join them, whether or not they have a relationship defined, although typically you would join them using the primary and foreign key columns

    however, you can join tables on whatever columns you want, regardless of whether relationships have been defined
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    teesside
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using MYSQL?

    Im in the same boat and im using Mysql

    Rich

  4. #4
    SitePoint Member Aber_Al's Avatar
    Join Date
    Dec 2004
    Location
    Wales
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ah ha that makes sense!

    r937: Thanks a lot! Makes sense now
    weewizard/rich: yeah I am using mysql.

    Thanks guys,

    Al.


Bookmarks

Posting Permissions

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