Précédent   Forum des professionnels en informatique > Bases de données > MySQL > Requêtes
Requêtes Forum d'entraide sur les requêtes MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 28/01/2011, 20h10   #1
apt
Membre du Club
 
Inscription : mai 2002
Messages : 526
Détails du profil
Informations forums :
Inscription : mai 2002
Messages : 526
Points : 42
Points : 42
Par défaut Champ id ambigue

Salut à tous,

En essayant de faire une requête SQL, je reçois cette erreur :

Citation:
requête SQL: Documentation

SELECT id, title, uploadfile, catmig, cat_id, rafia_cat.id, rafia_cat.title
FROM rafia_articles a, rafia_cat c
INNER JOIN rafia_cat ON a.cat_id = c.id
WHERE allow = 'yes'
ORDER BY rafia_articles.id DESC
LIMIT 0 , 3

MySQL a réponduocumentation
#1052 - Column 'id' in field list is ambiguous
Structure de la table :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
`rafia_articles` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `cat_id` int(255) NOT NULL DEFAULT '0',
  `title` varchar(100) collate latin1_general_ci NOT NULL DEFAULT '',
  `date_time` int(11) NOT NULL DEFAULT '0',
  `date` date NOT NULL DEFAULT '0000-00-00',
  `userid` int(11) NOT NULL DEFAULT '0',
  `name` varchar(100) collate latin1_general_ci NOT NULL DEFAULT '',
  `articles_head` text collate latin1_general_ci NOT NULL,
  `post` longtext collate latin1_general_ci,
  `allow` char(3) collate latin1_general_ci NOT NULL DEFAULT '',
  `inindex` int(1) NOT NULL DEFAULT '1',
  `inmenu` int(1) NOT NULL DEFAULT '1',
  `main` tinyint(1) NOT NULL DEFAULT '0',
  `catmig` int(1) NOT NULL DEFAULT '0',
  `reader` int(10) DEFAULT '0',
  `c_comment` int(10) DEFAULT '0',
  `sticky` tinyint(2) NOT NULL DEFAULT '0',
  `close` int(1) NOT NULL DEFAULT '0',
  `rating_total` int(10) NOT NULL DEFAULT '0',
  `ratings` int(10) NOT NULL DEFAULT '0',
  `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `lastuserid` int(11) NOT NULL DEFAULT '0',
  `timestamp` int(11) NOT NULL DEFAULT '0',
  `uploadfile` int(10) NOT NULL DEFAULT '0',
  `ues_editor` int(1) NOT NULL DEFAULT '0',
  `edit_by` varchar(255) collate latin1_general_ci NOT NULL DEFAULT '0',
  PRIMARY KEY  (`id`),
  KEY `timestamp` (`timestamp`),
  KEY `cat_id` (`cat_id`),
  KEY `userid` (`userid`),
  FULLTEXT KEY `post` (`post`),
  FULLTEXT KEY `articles_head` (`articles_head`),
  FULLTEXT KEY `title` (`title`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=6 ;
Structure de la table :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
`rafia_cat` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `ordercat` int(10) NOT NULL DEFAULT '0',
  `catType` int(3) NOT NULL DEFAULT '0',
  `subcat` int(10) NOT NULL DEFAULT '0',
  `title` varchar(100) collate latin1_general_ci NOT NULL DEFAULT '',
  `dsc` text collate latin1_general_ci NOT NULL,
  `dscin` text collate latin1_general_ci NOT NULL,
  `countopic` int(10) NOT NULL DEFAULT '0',
  `countcomm` int(10) NOT NULL DEFAULT '0',
  `lastpostid` int(11) NOT NULL DEFAULT '0',
  `moderateid` varchar(100) collate latin1_general_ci NOT NULL DEFAULT '0',
  `ismine` tinyint(2) NOT NULL DEFAULT '0',
  `groupost` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '0',
  `groupview` varchar(200) collate latin1_general_ci NOT NULL DEFAULT '0',
  `cat_email` varchar(255) collate latin1_general_ci DEFAULT NULL,
  `catClose` char(1) collate latin1_general_ci NOT NULL DEFAULT '0',
  `homeshow` int(4) NOT NULL DEFAULT '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=397 ;
Merci.
apt est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/01/2011, 20h46   #2
Membre Expert
 
Avatar de Madfrix
 
Inscription : juin 2007
Messages : 2 278
Détails du profil
Informations personnelles :
Localisation : France, Gironde (Aquitaine)

Informations forums :
Inscription : juin 2007
Messages : 2 278
Points : 2 324
Points : 2 324
Bonsoir,

c'est relativement parlant comme erreur non...?

Met un alias ici :

Madfrix est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/01/2011, 02h38   #3
Membre régulier
 
Inscription : août 2006
Messages : 169
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 169
Points : 82
Points : 82
Bonjour,

attention à bien mettre les alias, et ce n'est pas la peine de mettre la table rafia_cat dans le FROM si tu l'as déjà dans le inner join.
Code :
1
2
3
4
5
6
7
8
9
10
11
SELECT a.id,
       a.title,
       a.uploadfile,
       a.catmig,
       a.cat_id,
       c.id,
       c.title
  FROM rafia_articles AS a INNER JOIN rafia_cat AS c ON a.cat_id = c.id
 WHERE a.allow = 'yes'
ORDER BY a.id DESC
 LIMIT 0, 3
__________________
Cordialement.
ninikkhuet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/01/2011, 09h14   #4
apt
Membre du Club
 
Inscription : mai 2002
Messages : 526
Détails du profil
Informations forums :
Inscription : mai 2002
Messages : 526
Points : 42
Points : 42
Merci ninikkhuet et Madfrix
apt est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h04.


 
 
 
 
Partenaires

Hébergement Web