mysql_insert_id() and JOIN
mysql_insert_id() and JOIN
am 11.07.2009 06:58:05 von Emiliano Boragina
------=_NextPart_000_0015_01CA01CB.0A3BA3B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi again=85
I dont understand how to use this two=85
I read php.net and other sites, but dont understand...
=20
I have this four tables: table1, 2, 3 and 4
So the SELECT is like this?:
$query_select =3D "SELECT * FROM table1 FULL JOIN table2 FULL JOIN =
table3 FULL
JOIN table4 ON table1.id=3Dtable2.id=3Dtable3.id=3Dtable4.id ORDER BY id =
ASC=94;
mysql_query($query_select);
?>
This is with FULL JOIN... How identificate the left table if I want to =
use
LEFT JOIN?
How is the UPDATE?
And the INSERT I dont understand yet how is it?
I=92m not to do a link between tables in PHPMyAdmin?
=20
Thank you very... VERY... much!
+ =
_
// Emiliano Boragina _
// Dise=F1o & Comunicaci=F3n //////////////////
+ =
_
// emiliano.boragina@gmail.com /
// 15 40 58 60 02 ///////////////////////////
+ =
_
=20
------=_NextPart_000_0015_01CA01CB.0A3BA3B0--
Re: mysql_insert_id() and JOIN
am 11.07.2009 09:26:57 von Niel Archer
> Hi again=85
>=20
> I dont understand how to use this two=85
>=20
> I read php.net and other sites, but dont understand...
http://dev.mysql.com/doc/
Available in the major languages, pick your filter and start reading.
Having documentation in your own language may help a lot towards
understanding.
> I have this four tables: table1, 2, 3 and 4
>=20
> So the SELECT is like this?:
>=20
>
>=20
> $query_select =3D "SELECT * FROM table1 FULL JOIN table2 FULL JOIN table3=
FULL
> JOIN table4 ON table1.id=3Dtable2.id=3Dtable3.id=3Dtable4.id ORDER BY id =
ASC=94;
>=20
> mysql_query($query_select);
>=20
> ?>
>=20
> This is with FULL JOIN... How identificate the left table if I want to us=
e
> LEFT JOIN?
The left table is the table to the left of the join. So:
SELECT id FROM table1 LEFT JOIN table2...
table1 is the left table and table2 is the right table (if you were to
use a RIGHT JOIN).
>=20
> How is the UPDATE?
>=20
> And the INSERT I dont understand yet how is it?
UPDATEs and INSERTs follow the same procedure.
When you INSERT an entry into the main table, you then use the function
mysql_insert_id() which will give you the value of the last 'id' column
generated, which you can then use to insert data into the secondary
tables.
>=20
> I=92m not to do a link between tables in PHPMyAdmin?
>=20
> =20
>=20
> Thank you very... VERY... much!
>=20
If you are using MySQL 4.1 or later you should use the mysqli extension
and not the older mysql one. UNLESS you are relying on the older style
passwords, which is a BAD idea.
--
Niel Archer
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: mysql_insert_id() and JOIN
am 11.07.2009 16:07:55 von Emiliano Boragina
> Hi again.
>
> I dont understand how to use this two.
>
> I read php.net and other sites, but dont understand...
http://dev.mysql.com/doc/
Available in the major languages, pick your filter and start reading.
Having documentation in your own language may help a lot towards
understanding.
> I have this four tables: table1, 2, 3 and 4
>
> So the SELECT is like this?:
>
>
>
> $query_select = "SELECT * FROM table1 FULL JOIN table2 FULL JOIN table3
FULL
> JOIN table4 ON table1.id=table2.id=table3.id=table4.id ORDER BY id ASC";
>
> mysql_query($query_select);
>
> ?>
>
> This is with FULL JOIN... How identificate the left table if I want to use
> LEFT JOIN?
The left table is the table to the left of the join. So:
SELECT id FROM table1 LEFT JOIN table2...
table1 is the left table and table2 is the right table (if you were to
use a RIGHT JOIN).
>> With my 4 tables the sql is like this?:
>> SELECT * FROM table1 LEFT JOIN table2 LEFT JOIN table3 LEFT JOIN table4
WHERE table1.id = table2.id = table3.id = table4.id
>
> How is the UPDATE?
>
> And the INSERT I dont understand yet how is it?
UPDATEs and INSERTs follow the same procedure.
When you INSERT an entry into the main table, you then use the function
mysql_insert_id() which will give you the value of the last 'id' column
generated, which you can then use to insert data into the secondary
tables.
>> How is the the slq query with "mysql_insert_id()"?
>
> I'm not to do a link between tables in PHPMyAdmin?
>
>
>
> Thank you very... VERY... much!
>
If you are using MySQL 4.1 or later you should use the mysqli extension
and not the older mysql one. UNLESS you are relying on the older style
passwords, which is a BAD idea.
>> I dont know what version I use =S
>> THANKS A LOT NEIL
--
Niel Archer
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: mysql_insert_id() and JOIN
am 12.07.2009 19:33:48 von Emiliano Boragina
Sorry my question... but why I must use JOIN if I can use SELECT * FROM
table1 AND table2 AND table3 WHERE table1.id=3Dtable2.id=3Dtable3 not?
thanks
+ =
_
// Emiliano Boragina _
// Dise=F1o & Comunicaci=F3n //////////////////
+ =
_
// emiliano.boragina@gmail.com /
// 15 40 58 60 02 ///////////////////////////
+ =
_
-----Mensaje original-----
De: Emiliano Boragina [mailto:emiliano.boragina@gmail.com]=20
Enviado el: S=E1bado, 11 de Julio de 2009 11:08 a.m.
Para: 'php-db@lists.php.net'
Asunto: RE: [PHP-DB] mysql_insert_id() and JOIN
> Hi again=85
>=20
> I dont understand how to use this two=85
>=20
> I read php.net and other sites, but dont understand...
http://dev.mysql.com/doc/
Available in the major languages, pick your filter and start reading.
Having documentation in your own language may help a lot towards
understanding.
> I have this four tables: table1, 2, 3 and 4
>=20
> So the SELECT is like this?:
>=20
>
>=20
> $query_select =3D "SELECT * FROM table1 FULL JOIN table2 FULL JOIN =
table3
FULL
> JOIN table4 ON table1.id=3Dtable2.id=3Dtable3.id=3Dtable4.id ORDER BY =
id ASC=94;
>=20
> mysql_query($query_select);
>=20
> ?>
>=20
> This is with FULL JOIN... How identificate the left table if I want to =
use
> LEFT JOIN?
The left table is the table to the left of the join. So:
SELECT id FROM table1 LEFT JOIN table2...
table1 is the left table and table2 is the right table (if you were to
use a RIGHT JOIN).
>> With my 4 tables the sql is like this?:
>> SELECT * FROM table1 LEFT JOIN table2 LEFT JOIN table3 LEFT JOIN =
table4
WHERE table1.id =3D table2.id =3D table3.id =3D table4.id
>=20
> How is the UPDATE?
>=20
> And the INSERT I dont understand yet how is it?
UPDATEs and INSERTs follow the same procedure.
When you INSERT an entry into the main table, you then use the function
mysql_insert_id() which will give you the value of the last 'id' column
generated, which you can then use to insert data into the secondary
tables.
>> How is the the slq query with "mysql_insert_id()"?
>=20
> I=92m not to do a link between tables in PHPMyAdmin?
>=20
> =20
>=20
> Thank you very... VERY... much!
>=20
If you are using MySQL 4.1 or later you should use the mysqli extension
and not the older mysql one. UNLESS you are relying on the older style
passwords, which is a BAD idea.
>> I dont know what version I use =3DS
>> THANKS A LOT NEIL
--
Niel Archer
--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_insert_id() and JOIN
am 12.07.2009 20:12:53 von Niel Archer
> Sorry my question... but why I must use JOIN if I can use SELECT * FROM
> table1 AND table2 AND table3 WHERE table1.id=3Dtable2.id=3Dtable3 not?
> thanks
You can not use that syntax on MySQL (at least not on v5.0 or v5.1, I
do not know about earlier versions).
> // Emiliano Boragina _
> // Dise=F1o & Comunicaci=F3n //////////////////
--
Niel Archer
niel.archer (at) blueyonder.co.uk
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: mysql_insert_id() and JOIN
am 13.07.2009 16:46:33 von Phpster
[snip]
> Sorry my question... but why I must use JOIN if I can use SELECT * FROM
> table1 AND table2 AND table3 WHERE table1.id=3Dtable2.id=3Dtable3 not?
> thanks
>
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0_
[/snip]
select table1.field1, table1.field2, table2.field3, table2.field4,
table3.field5 from
table1, table 2, table3
where table1.id=3Dtable2.id and table1.id =3D table3.id
vs
select table1.field1, table1.field2, table2.field3, table2.field4,
table3.field5
from
table1
inner join table2 on table1.id =3D table2.id
outer join table3 on table1.id =3D table3.id
The first statement only does INNER JOINS, the seconds allows for
INNER and OUTER joins, so its more flexible in terms of what you want
the data to be
Bastien
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php