Forum : MySQL

MySQL

Faire une jointure

ben jai une erreur et je c pas trop pk elle ne öarche pas completement

Par clemclem, le Mardi 8 Mai 2007 à 09:53:44
Autorisé : HTML - Smileys - Balises - Multipost

Formulaire : Nouveau message

Sujets

Par Zéfling, le Mardi 8 Mai 2007 à 12:03:25
Avatar
Webmaster

Petit cours de MySQL ^_^' pour rendre des requêtes lisibles

Faire des retours à la ligne !!!!

Exemple :

CODE :

SELECT a.`a`, a.`b`, 
      b.`c`, b.`d`, b.`e`
FROM `Nom_de_la_table_long` a
    LEFT JOIN `autre_nom_long_de_table` b
           ON a.`a` = b.`w`
WHERE a.`x` = '10'
GROUP BY a.`a`

Y'a pas que le code php qui doit être lisible, quand une requête MySQL est longue il y a rien de plus chiant que d'avoir une bouillie à lire ^^'

Mieux vaut ne rien dire et passer pour un con que de l’ouvrir et ne laisser aucun doute à ce sujet.
Par Togira, le Mardi 8 Mai 2007 à 10:04:57
Avatar
Membre

Re :


mais des que j'ajoute la ligne
INNER JOIN llx_product_geo ON pgeo.prod_ref = llx_product.rowid
sa ne marche plus, il me dit ke
"#1054 - Champ 'llx_product.rowid' inconnu dans on clause "

clemclem- 08/05/2007 09:53

Juste une erreur d'écriture apparemment =)

EDIT :
Remplace par :

INNER JOIN llx_product_geo ON pgeo.prod_ref = llx_product_geo.rowid

Par clemclem, le Mardi 8 Mai 2007 à 09:59:50
Avatar
Membre

celle ci est deja plus propre

SELECT p.rowid, p.ref, p.label, p.description, p.note, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.envente, p.nbvente, p.fk_product_type, p.duration, p.seuil_stock_alerte, p.canvas, p.stock_commande, p.stock_loc, p.weight, p.weight_units, pgeo.id, pgeo.prod_ref, pgeo.pays, pgeo.region, pgeo.ville, pgeo.dispo, pgeo.notes
FROM llx_product AS p, llx_product_geo AS pgeo
WHERE pgeo.prod_ref = p.rowid

et renvoi la meme chose

Par clemclem, le Mardi 8 Mai 2007 à 09:58:04
Avatar
Membre

jj'remplacer par
SELECT p.rowid, p.ref, p.label, p.description, p.note, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.envente, p.nbvente, p.fk_product_type, p.duration, p.seuil_stock_alerte, p.canvas, p.stock_commande, p.stock_loc, p.weight, p.weight_units, pgeo.id, pgeo.prod_ref, pgeo.pays, pgeo.region, pgeo.ville, pgeo.dispo, pgeo.notes
FROM llx_product AS p, llx_product_geo AS pgeo
WHERE pgeo.prod_ref =8
AND p.rowid =8


et sa marche, je ne c pas si le resultat et vraiment le meme, ou c'est une facon detournee d'obtenir la meme chose, mais je pense que sa suffira

Par clemclem, le Mardi 8 Mai 2007 à 09:53:44
Avatar
Membre

cette requete marche tres bien,

SELECT p.rowid, p.ref, p.label, p.description, p.note, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.envente,
p.nbvente, p.fk_product_type, p.duration, p.seuil_stock_alerte, p.canvas, p.stock_commande, p.stock_loc, p.weight,
p.weight_units, pgeo.id, pgeo.prod_ref, pgeo.pays, pgeo.region, pgeo.ville, pgeo.dispo, pgeo.notes
FROM llx_product as p, llx_product_geo as pgeo

mais des que j'ajoute la ligne
INNER JOIN llx_product_geo ON pgeo.prod_ref = llx_product.rowid
sa ne marche plus, il me dit ke
"#1054 - Champ 'llx_product.rowid' inconnu dans on clause "


si tu veux la structure des tables, la voila :

CREATE TABLE `llx_product` (
`rowid` int(11) NOT NULL auto_increment,
`datec` datetime default NULL,
`tms` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`ref` varchar(16) collate latin1_german1_ci NOT NULL,
`label` varchar(255) collate latin1_german1_ci NOT NULL,
`description` text collate latin1_german1_ci,
`note` text collate latin1_german1_ci,
`price` double default NULL,
`price_ttc` float(12,4) default '0.0000',
`price_base_type` varchar(3) collate latin1_german1_ci default 'HT',
`tva_tx` double default NULL,
`fk_user_author` int(11) default NULL,
`envente` tinyint(4) default '1',
`nbvente` int(11) default '0',
`fk_product_type` int(11) default '0',
`duration` varchar(6) collate latin1_german1_ci default NULL,
`stock_propale` int(11) default '0',
`stock_commande` int(11) default '0',
`seuil_stock_alerte` int(11) default '0',
`stock_loc` varchar(10) collate latin1_german1_ci default NULL,
`gencode` varchar(255) collate latin1_german1_ci default NULL,
`weight` float default NULL,
`weight_units` tinyint(4) default NULL,
`canvas` varchar(15) collate latin1_german1_ci default '',
PRIMARY KEY (`rowid`),
UNIQUE KEY `uk_product_ref` (`ref`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=41 ;

et


CREATE TABLE `llx_product_geo` (
`id` int(11) NOT NULL auto_increment,
`prod_ref` int(11) NOT NULL,
`pays` int(11) NOT NULL,
`region` int(11) NOT NULL,
`ville` int(11) NOT NULL,
`dispo` int(1) NOT NULL,
`notes` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;