Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-03-2005, 11:33 PM   #1
Registered: Sep 2003
Location: Suwon, Korea
Distribution: Slackware 14
Posts: 288

Rep: Reputation: 32
mysql relationships question

Im very new to mysql, and I'm trying to do a small database to link campers to addresses and specific camps and such. I know about setting primary keys and such, but one point eludes me. How does mysql actually link info in different tables properly? I have a name table, an address table, a camp table, and so on, but when I enter data into each of these tables seperately, how does mysql know what camp a person is in? I have the primary key name_id, and in every other table, I have this as a secondary key, as my manual explains to do, but it never explains how mysql will know what data goes together. Sorry this is so vague, I know so little I don't really know what it is I don't know. I've read lots of material on this, but nothing really covers this simple question.
Old 03-04-2005, 12:21 AM   #2
LQ Newbie
Registered: Feb 2005
Location: Australia
Distribution: Debian, Reformed Slackwareist
Posts: 20

Rep: Reputation: 0
This url from the MySQL tutorial gives a brief intro to implicit joins

You could search the MySQL for more details about joins

but just quickly something like

SELECT * FROM name LEFT JOIN address ON name.name_id = address.name_id;

might be what your looking for.

the ON clause tells MySQL to associate the data.
Old 03-04-2005, 01:57 AM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.7, Centos 5.10
Posts: 16,936

Rep: Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215Reputation: 2215
You should look into foreign keys eg:

This is added to the create statement on child tables of the Names table (eg Addresses table). When you add a row to Addresses, the DB will only allow it if a row exists on the Names table with the same vale for the Name column on both tables.
FOREIGN KEY (col_on_this_table) REFERENCES other_table (col_on_other_table)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 09:44 AM
Nessus Plugin Variable Relationships BoarderX Linux - Software 1 04-20-2005 08:06 PM
Samba 3.0 Alpha 23 Adding Trusted Relationships Vishi Linux - Networking 0 05-14-2003 03:46 AM
MySQL question Glover Linux - Software 3 08-22-2002 08:13 PM
MySQL Relationships Question? RecoilUK Linux - General 1 08-02-2001 07:05 PM

All times are GMT -5. The time now is 12:56 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration