Unix Technical Forum

SQL query - problem

This is a discussion on SQL query - problem within the MySQL forums, part of the Database Server Software category; --> Hello, I have the following structure of my database: Table: Depot (ID_Depot, Name, City, Country) Table: Route (ID_Route, ID_Origin_Depot, ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-13-2008, 01:59 PM
mark
 
Posts: n/a
Default SQL query - problem

Hello,

I have the following structure of my database:

Table: Depot (ID_Depot, Name, City, Country)
Table: Route (ID_Route, ID_Origin_Depot, ID_Dest_Depot)

and would like to create a view like that:
Depot_Origin_Name, Depot_Origin_City, Depot_Dest_Name, Depot_Dest_City

how can I make it in mysql? Is such structure of database efficient
(what should I index to improve the performance)?

Thanks, Mark
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-13-2008, 01:59 PM
Paul Lautman
 
Posts: n/a
Default Re: SQL query - problem

mark wrote:
> Hello,
>
> I have the following structure of my database:
>
> Table: Depot (ID_Depot, Name, City, Country)
> Table: Route (ID_Route, ID_Origin_Depot, ID_Dest_Depot)
>
> and would like to create a view like that:
> Depot_Origin_Name, Depot_Origin_City, Depot_Dest_Name, Depot_Dest_City
>
> how can I make it in mysql?

CREATE VIEW mark_view AS
SELECT
o.Name Depot_Origin_Name,
o.City Depot_Origin_City,
d.Name Depot_Dest_Name,
d.City Depot_Dest_City
FROM Route r
JOIN Depot o ON r.ID_Origin_Depot = o.ID_Depot
JOIN Depot d ON r.ID_Origin_Depot = d.ID_Depot
WHERE r.ID_Route = 'route_ir'

> Is such structure of database efficient

It depends on what you want to do with it.

> (what should I index to improve the performance)?

It depends on what you want to do with it, although ID_Depot should be a
Primary Key

> Thanks, Mark

You're welcome



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com