Q - Can define how tables are linked (joined together) when you set them up in MySQL, rather than having to specify the join each time that you SELECT data from the tables?
What a great (and logical) idea, but it's not straightforward / automatically available. The current / default system in the basic MySQL is somewhat illogical, as what can join up to what really ought to be specified with the database definition, and not as the data is extracted ... where erroneous (and silly) joins can be specified, and furthermore the user of the data needs to understand its structure.
There are some tools / approaches which can help towards implementing a system - basically, you want to be able to specify the orange bits in the following when calling up data, and have the magenta bit always / automatically provided from design time:
Select f1, f2, f3, f4 from t1 left join t2 on f2 = f6 where f7 > 1000
Some things that may help:
Views - From release 5.0, MySQL has included views which allow you to define a VIEW onto your data, and such views may include JOINs (gets a bit tricky at UPDATE time); a joined view - especially in conjunction with Stored Procedures - will help towards your goal.
Stored Procedures - Again, from Release 5.0. You don't need to specify the full series of MySQL statements every time, but can store them to be run each time you press the "Green Button" to make a request.
[stored procedure resources]
Frameworks such as Ruby on Rails - The "Model" element of frameworks such as Ruby on Rails (and others too) allow / encourage you to specify rather more details that you would normally present to MySQL, including the limits that need to be applied to data in certain fields, and relationships.
[Ruby on Rails sample]
Encapsulation of data within objects - If you access your data / database through objects, you'll be getting the ability to encapsulate the JOIN so that it won't be visible to / the concern of the user of your class of objects
Libraries of valid joins - I've found it very useful to hold libraries of valid joins in certain applications, so that only sensible joins are performed. A single composite join if you have a lot of tables (one of our customer joined 27 tables!) can be inefficient - but a menu scheme which only allows things which have been predefined can work wonders. Table of allowed joins described fully
[here] and available for you to try
[here]
(written 2010-05-02)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
S163 - Stored Procedures in MySQL [2446] Learn about MySQL stored procedures - (2009-10-09)
[2447] MySQL stored procedures / their use on the web from PHP - (2009-10-10)
S154 - MySQL - Designing an SQL Database System [59] MySQL - Pivot tables - (2004-09-22)
[361] Binary Large Objects or bars - (2005-06-27)
[375] Oops - I got my initial database design wrong - (2005-07-12)
[494] MySQL - a score of things to remember - (2005-11-12)
[515] MySQL - an FAQ - (2005-12-03)
[666] Database design - get it right from first principles - (2006-04-02)
[918] Databases needn't be frightening, hard or expensive - (2006-11-08)
[937] Display an image from a MySQL database in a web page via PHP - (2006-11-22)
[945] Code quality counts - (2006-11-26)
[1423] MySQL - table design and initial testing example - (2007-11-06)
[1575] Database design for a shopping application (MySQL) - (2008-03-15)
[1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
[2053] What a difference a MySQL Index made - (2009-02-25)
[2085] MySQL - licensing issues, even with using the name - (2009-03-16)
[2204] Images in a database? How big is a database? (MySQL) - (2009-05-28)
[3270] SQL - Data v Metadata, and the various stages of data selection - (2011-04-29)
[3361] Blowing our own trumpet - MySQL resources - (2011-07-18)
[3494] Databases - when to treat the rules as guidelines - (2011-10-23)
[4426] FileMaker Day to Unix Time conversion - (2015-02-15)
Q916 - Object Orientation and General technical topics - Database design principles [572] Giving the researcher power over database analysis - (2006-01-22)
Some other Articles
You do not just fly - that is just part of the journeyVoting day - UK General ElectionGoing off at a tangent, for a rambleViews of WessexDelegate Question - defining MySQL table relationships as you create the tablesMonitoring the success and traffic of your web siteContainment, Associative Objects, Inheritance, packages and modulesModel - View - Controller demo, Sqlite - Python 3 - Qt4Connecting Python to sqlite and MySQL databasesPyQt (Python and Qt) and wxPython - GUI comparison