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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| 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 |