Gumbo
Erfahrenes Mitglied
Ich benötige eine verknüpfte Abfrage zwischen zwei Tabellen:
CREATE TABLE `articles` (
`article_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`author_id` INT UNSIGNED NOT NULL,
`title` VARCHAR(255) NOT NULL,
`date` TIMESTAMP(14) NOT NULL,
`modified` TIMESTAMP(14) NOT NULL,
PRIMARY KEY (`article_id`)
 
;
CREATE TABLE `article_pages` (
`page_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`target_id` INT UNSIGNED NOT NULL,
`page` TINYINT NOT NULL,
`sub_title` VARCHAR(255) NOT NULL,
`content` TEXT NOT NULL,
PRIMARY KEY (`page_id`)
 
;
Die Abfrage soll neben dem Inhalt sowohl die aktuellen als auch die Gesamtanzahl der Seiten ausgeben. Ich habe mich bereits etwas versucht, scheitere aber immer wieder daran neben der aktuellen Seite auch die Gesamtanzahl der Seiten abzufragen:
SELECT
articles.author_id;
users.login AS author,
articles.title,
articles.date,
articles.modified,
article_pages.content,
COUNT(article_pages.page) AS pages
FROM
`articles`,
`article_pages`,
`users`
WHERE (
article_pages.target_id=1
AND article_pages.page=1
AND users.user_id=articles.author_id
 
GROUP BY
articles.author_id
Ich hoffe ihr könnte mir bei meinem Problem helfen.
CREATE TABLE `articles` (
`article_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`author_id` INT UNSIGNED NOT NULL,
`title` VARCHAR(255) NOT NULL,
`date` TIMESTAMP(14) NOT NULL,
`modified` TIMESTAMP(14) NOT NULL,
PRIMARY KEY (`article_id`)
 

CREATE TABLE `article_pages` (
`page_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`target_id` INT UNSIGNED NOT NULL,
`page` TINYINT NOT NULL,
`sub_title` VARCHAR(255) NOT NULL,
`content` TEXT NOT NULL,
PRIMARY KEY (`page_id`)
 

Die Abfrage soll neben dem Inhalt sowohl die aktuellen als auch die Gesamtanzahl der Seiten ausgeben. Ich habe mich bereits etwas versucht, scheitere aber immer wieder daran neben der aktuellen Seite auch die Gesamtanzahl der Seiten abzufragen:
SELECT
articles.author_id;
users.login AS author,
articles.title,
articles.date,
articles.modified,
article_pages.content,
COUNT(article_pages.page) AS pages
FROM
`articles`,
`article_pages`,
`users`
WHERE (
article_pages.target_id=1
AND article_pages.page=1
AND users.user_id=articles.author_id
 

GROUP BY
articles.author_id
Ich hoffe ihr könnte mir bei meinem Problem helfen.
Zuletzt bearbeitet: