dbTalk Databases Forums  

new to databases, multiple relations

mailing.database.myodbc mailing.database.myodbc


Discuss new to databases, multiple relations in the mailing.database.myodbc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pedro X Gomes-Fabre
 
Posts: n/a

Default new to databases, multiple relations - 07-07-2003 , 10:53 AM






Hi all,

I have to create a database where the elements of a table are related to
elements on the same table. What is the best (optimised) way to do that?

I came with the model:

CREATE TABLE locations(
location_id int(11) auto_increment,
location_name varchar(50) NOT NULL default '',
UNIQUE KEY idx1 (id)
) type MyISAM;

CREATE TABLE relations(
relation_id int(11) auto_increment,
location_id1 int(11) NOT NULL,
location_id2 int(12) NOT NULL,
distance float NOT NULL default '0',
UNIQUE KEY idx1 (location_id1, location_id2)
UNIQUE KEY idx2 (relation_id)
) type MyISAM;



And the query will be like:

SELECT location_name, location_name, distance
FROM locations AS l, relations AS r
WHERE l.location_id=r.location_id1
AND l.location_id=r.location_id2;


Thanks for your help
Pedro


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw


Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.