mysql_insert_id() and JOIN

------=_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...



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?



Thank you very... VERY... much!

+ =
_
// Emiliano Boragina _
// Dise=F1o & Comunicaci=F3n //////////////////
+ =
_
// emiliano.boragina [at] gmail.com /
// 15 40 58 60 02 ///////////////////////////
+ =
_




------=_NextPart_000_0015_01CA01CB.0A3BA3B0--
Emiliano Boragina [ Sa, 11 Juli 2009 06:58 ] [ ID #2008192 ]

Re: mysql_insert_id() and JOIN

> Hi again=85
>
> I dont understand how to use this two=85
>
> 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 =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 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).

>
> 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.

>
> I=92m 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.

--
Niel Archer



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Niel Archer [ Sa, 11 Juli 2009 09:26 ] [ ID #2008194 ]

RE: mysql_insert_id() and JOIN

> 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
Emiliano Boragina [ Sa, 11 Juli 2009 16:07 ] [ ID #2008197 ]

RE: mysql_insert_id() and JOIN

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 [at] gmail.com /
// 15 40 58 60 02 ///////////////////////////
+ =
_


-----Mensaje original-----
De: Emiliano Boragina [mailto:emiliano.boragina [at] gmail.com]
Enviado el: S=E1bado, 11 de Julio de 2009 11:08 a.m.
Para: 'php-db [at] lists.php.net'
Asunto: RE: [PHP-DB] mysql_insert_id() and JOIN


> Hi again=85
>
> I dont understand how to use this two=85
>
> 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 =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?

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


>
> 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=92m 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 =3DS

>> 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
Emiliano Boragina [ So, 12 Juli 2009 19:33 ] [ ID #2008279 ]

Re: mysql_insert_id() and JOIN

> 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
Niel Archer [ So, 12 Juli 2009 20:12 ] [ ID #2008281 ]

Re: mysql_insert_id() and JOIN

[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
Phpster [ Mo, 13 Juli 2009 16:46 ] [ ID #2008391 ]
PHP » gmane.comp.php.database » mysql_insert_id() and JOIN

Vorheriges Thema: simple INSERT statement with placeholders failing. I don't understand why.
Nächstes Thema: resize 10 upload image