par
Cyrano » 03 janv. 2007, 12:15
Je ne saisis pas : quel résultat obtiens-tu au juste ? En reprenant exactement ta structure, j'obtiens bien le résultat attendu
Voilà exactement ce que j'ai fait :
Code : Tout sélectionner
DROP TABLE IF EXISTS `links`;
CREATE TABLE `links`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(32) NOT NULL,
`url` VARCHAR(128) NOT NULL
)ENGINE = MyISAM;
DROP TABLE IF EXISTS `tags`;
CREATE TABLE `tags`(
`link` INT(11) NOT NULL,
`tag` VARCHAR(32)
)ENGINE = MyISAM;
INSERT INTO `links` VALUES
(1, 'lien1', 'www.lien1.com'),
(2, 'lien2', 'www.lien2.com'),
(3, 'lien3', 'www.lien3.com');
INSERT INTO `tags` VALUES
(1, 'tag1'),
(1, 'tag2'),
(1, 'tag3'),
(2, 'tag2'),
(2, 'tag3'),
(3, 'tag1'),
(3, 'tag3');
J'ai donc les tables :
Code : Tout sélectionner
mysql> SELECT * FROM `links`;
+----+-------+---------------+
| id | title | url |
+----+-------+---------------+
| 1 | lien1 | www.lien1.com |
| 2 | lien2 | www.lien2.com |
| 3 | lien3 | www.lien3.com |
+----+-------+---------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM `tags`;
+------+------+
| link | tag |
+------+------+
| 1 | tag1 |
| 1 | tag2 |
| 1 | tag3 |
| 2 | tag2 |
| 2 | tag3 |
| 3 | tag1 |
| 3 | tag3 |
+------+------+
7 rows in set (0.00 sec)
Et j'obtiens :
Code : Tout sélectionner
mysql> SELECT links.id, links.title, links.url
-> FROM tags, links
-> WHERE tags.tag = 'tag1'
-> AND tags.link = links.id;
+----+-------+---------------+
| id | title | url |
+----+-------+---------------+
| 1 | lien1 | www.lien1.com |
| 3 | lien3 | www.lien3.com |
+----+-------+---------------+
2 rows in set (0.00 sec)
Je ne saisis pas : quel résultat obtiens-tu au juste ? En reprenant exactement ta structure, j'obtiens bien le résultat attendu :-k
Voilà exactement ce que j'ai fait :
[code]DROP TABLE IF EXISTS `links`;
CREATE TABLE `links`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(32) NOT NULL,
`url` VARCHAR(128) NOT NULL
)ENGINE = MyISAM;
DROP TABLE IF EXISTS `tags`;
CREATE TABLE `tags`(
`link` INT(11) NOT NULL,
`tag` VARCHAR(32)
)ENGINE = MyISAM;
INSERT INTO `links` VALUES
(1, 'lien1', 'www.lien1.com'),
(2, 'lien2', 'www.lien2.com'),
(3, 'lien3', 'www.lien3.com');
INSERT INTO `tags` VALUES
(1, 'tag1'),
(1, 'tag2'),
(1, 'tag3'),
(2, 'tag2'),
(2, 'tag3'),
(3, 'tag1'),
(3, 'tag3');[/code]
J'ai donc les tables :
[code]mysql> SELECT * FROM `links`;
+----+-------+---------------+
| id | title | url |
+----+-------+---------------+
| 1 | lien1 | www.lien1.com |
| 2 | lien2 | www.lien2.com |
| 3 | lien3 | www.lien3.com |
+----+-------+---------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM `tags`;
+------+------+
| link | tag |
+------+------+
| 1 | tag1 |
| 1 | tag2 |
| 1 | tag3 |
| 2 | tag2 |
| 2 | tag3 |
| 3 | tag1 |
| 3 | tag3 |
+------+------+
7 rows in set (0.00 sec)[/code]
Et j'obtiens :
[code]mysql> SELECT links.id, links.title, links.url
-> FROM tags, links
-> WHERE tags.tag = 'tag1'
-> AND tags.link = links.id;
+----+-------+---------------+
| id | title | url |
+----+-------+---------------+
| 1 | lien1 | www.lien1.com |
| 3 | lien3 | www.lien3.com |
+----+-------+---------------+
2 rows in set (0.00 sec)[/code]