How to write an INNER JOIN QUERY in Mysql
Posted by condealmasy (condealmasy), 3 January 2003Hello.
I have a problem with this Inner Join Query:
SELECT logins.log_log, logins.log_pas, logins.log_cli_id, client_cli_nom, vehicle.veh_pla, vehicle.veh_cli_id, vehicle.veh_sc_ser, sc.sc_ser
FROM logins INNER JOIN (client INNER JOIN (vehicle INNER JOIN sc ON vehicle.veh_sc_ser = sc.sc_ser) ON client.cli_id = vehicle.veh_cli_id) ON logins.log_cli_id = client.cli_id
WHERE ((logins.log_log)=' User1 ') AND ((logins_cliente.log_pas)=' Password 1'));
It returns an an error where the first INNER JOIN starts.
This is how I know how to make those BIG INNER JOINS Queries. I'm new with Mysql so I suppose this type of database works differently with the INNER JOINS.
What I'm trying to do is find the client, vehicle and sc from the logins table, which is the table that relates to the client table, which relates to the vehicle table and so forth.
Posted by admin (Graham Ellis), 4 January 2003Although INNER is a keyword in MySQL, you'll find remarkably little reference to it in the books on MySQL. This is because (from the MySQL reference manual):
Here's an example of a join using the shorter "," notation:
In my example, I've only joined two tables, but you could just as well join 3, 4 or more and the syntax is much easier than fighting nested INNER JOINs!
Technical note: If you join with ",", you use a WHERE clause to specify how the tables are to be joined; if you omit the where clause, you'll discover that your result set has every record in each incoming table matched to every record in each of the other incoming tables that you specified. In my sample data set, which has our 343 technical books (including 26 on MySQL!) and 582 authors, that would give me a result set of 199626 records.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho