Unix Technical Forum

How to join several MySQL tables

This is a discussion on How to join several MySQL tables within the MySQL forums, part of the Database Server Software category; --> I have the following 4 MySQL tables: table1 - entry11 - entry12 - entry13 - entry14 table2 - entry21 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:33 AM
Stefan Mueller
 
Posts: n/a
Default How to join several MySQL tables

I have the following 4 MySQL tables:

table1
- entry11
- entry12
- entry13
- entry14

table2
- entry21
- entry22
- entry23

table3
- entry31
- entry32
- entry33
- entry34
- entry35

table4
- entry41
- entry42
- entry43

The relations between the different tables are:
entry21 = entry12
entry31 = entry22
entry41 = entry23

The output should be sorted with the following criterions:
1. entry12 (ascending)
2. entry22 (ascending)
3. entry23 (ascending)
4. entry34 (descending)
5. entry42 (ascending)
6. entry43 (ascending)

I've not much experience with MySQL but I think I have somehow to join
these 4 tables to a temporary table (e.g. joined-table) so that I can
do
$db_query = "SELECT * FROM joined-table ORDER BY entry12 ASC, entry22
ASC, entry23 ASC, entry34 DESC, entry42 ASC, entry43 ASC";

Is that correct and if yes, how can I join these 4 tables?
Will this joined table only be available in the memory? If yes, how
long will this joined table be available in the memory?

Regards
Stefan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:33 AM
Peter H. Coffin
 
Posts: n/a
Default Re: How to join several MySQL tables

On 12 Nov 2006 06:51:38 -0800, Stefan Mueller wrote:
> $db_query = "SELECT * FROM joined-table ORDER BY entry12 ASC, entry22
> ASC, entry23 ASC, entry34 DESC, entry42 ASC, entry43 ASC";
>
> Is that correct and if yes, how can I join these 4 tables?
> Will this joined table only be available in the memory? If yes, how
> long will this joined table be available in the memory?


http://dev.mysql.com/doc/refman/5.0/en/join.html

The join lasts as long as the query runs. Don't worry about that being
short-lived. Joining is the core reason for Relational Databases to
exist, so joining is very fast if an appropriate index is available.
Worry about what kind of index is available only after your query has
become unacceptably slow.

--
12. One of my advisors will be an average five-year-old child. Any flaws in my
plan that he is able to spot will be corrected before implementation.
--Peter Anspach's list of things to do as an Evil Overlord
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 04:48 PM.


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