Ubuntu 7.10 Mysql 5
Given these 2 tables:
-----------------------------
CREATE TABLE `bateaux_copy` (
`id` int(10) unsigned NOT NULL auto_increment,
`annee` int(10) unsigned NOT NULL,
`nom` varchar(254) character set utf8 collate utf8_unicode_ci
NOT NULL default ' ',
`tonnage` int(10) unsigned default NULL,
`port` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`depart` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`dest` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`notes` text character set utf8 collate utf8_unicode_ci,
`capitaine` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
PRIMARY KEY (`id`)
)
CREATE TABLE `passagers` (
`id` int(10) unsigned NOT NULL auto_increment,
`annee` int(11) default NULL,
`bateau` int(11) default NULL,
`prenom` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`nom` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`metier` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
`origine` varchar(254) character set utf8 collate
utf8_unicode_ci NOT NULL default ' ',
PRIMARY KEY (`id`)
)
------------------
I want to produce a list of all "passagers" gouped by passagers.annee
and passagers.bateau replacing passagers.bateau by bateaux.name without
using subroutines like while(){while(){While()}}}
I tried different subselect but without success.
Is it possible?
Thanks
What have you tried? An example query with sample data, result you are
getting and what the expected result should be.
Assuming that bateaux is a foreign key in passengers that matches the id
in bateaux_copy:
select passengers.annee, bateaux_copy.nom from passengers
join bateachx_copy on (beteaux_copy.id = passengers.bateaux)
group by passengers.annee
(untested)
'select passagers.*, bateaux.id as bid, bateaux.nom as bnom from
passagers join bateaux on (bateaux.id=passagers.bateau) order by
passagers.annee, passagers.bateau'
This leads to a list ordered as expected but with fields bnom and annee
repeated.
I expect :
1989
Titanic
McBean, Jonathan laborer London,Eng
Darmouth, Jos. mechanic eng. Australia
...
Blue Nose
Jefferson, Thomas president USA
...
1990
Titanic
Buddy, Jos terrorist Russia
...
> 'select passagers.*, bateaux.id as bid, bateaux.nom as bnom from
> passagers join bateaux on (bateaux.id=passagers.bateau) order by
> passagers.annee, passagers.bateau'
>
> This leads to a list ordered as expected but with fields bnom and annee
> repeated.
>
> I expect :
>
> 1989
> Titanic
> McBean, Jonathan laborer London,Eng
> Darmouth, Jos. mechanic eng. Australia
> ...
> Blue Nose
> Jefferson, Thomas president USA
> ...
>
> ...
What exactly do you expect in the annee field for Blue Nose? Do you want
"nothing" in that field?
--
Erick
Bateaux.id = passagers.bateau
The Bateaux table is a node.
The only relevant information here is bateaux.id that corresponds to
passagers.bateau and bateaux.nom as far as the expected list is
concerned. Nothing to do with the request here.
The list gives passengers year of arrival, ship they were on and some
general interest passenger infos as job and where they com from.
I understand that. It's your "...but with fields bnom and annee
repeated..." which I don't get.
In my perception, you should get something like:
1989 | Titanic | McBean, Jonathan | laborer | London,Eng
1989 | Titanic | Darmouth, Jos. | mechanic| Australia
1989 | Titanic | ... | ... | ...
1992 | BlueNose| Jefferson, Th. | president| Washington
1992 | BlueNose| Usenet Bill | poster | France
etc.
Isn't that what you want for your application, which would turn this into
the presentation that you want to offer the end user?
--
Erick
In the request ... 'select bateaux.nom as bnom'. bnom is then the name
of the field I'll use to retrieve the related data.
> In my perception, you should get something like:
>
> 1989 | Titanic | McBean, Jonathan | laborer | London,Eng
> 1989 | Titanic | Darmouth, Jos. | mechanic| Australia
> 1989 | Titanic | ... | ... | ...
> 1992 | BlueNose| Jefferson, Th. | president| Washington
> 1992 | BlueNose| Usenet Bill | poster | France
>
> etc.
>
>
> Isn't that what you want for your application, which would turn this into
> the presentation that you want to offer the end user?
>
Exactly.