MySQL Forums
Forum List  »  German

Problem mit SUBSELECT
Posted by: Thilo Habenreich
Date: November 24, 2008 02:18AM

Hi ich habe zwei Tabellen die eine enthält Hauptkategorien und die andere zugehörige Unterkategorien. Ziel ist es mit einem(!) Statement möglichst die Hauptkategorie + ihrer Unterkategorien aus der Datenbank zu holen. Ein JOIN bietet sich nicht an, da manche Hauptkategorien keine Unterkategorie besitzen können und somit aus dem Ergebnis rausfallen würden. Hier mal meine Statement wie es bisher ist:

$sql=' SELECT c.name, c.id as cat_id, c.namehtml,
(SELECT sc.id FROM subcat as sc WHERE c.id=sc.parent_id LIMIT 1) as subcat
FROM `cat` as c ORDER BY c.name';

Das funktioniert mit dem LIMIT 1 ja ganz prima nur bekomme ich so immer nur 1 Unterkategorie, was ja nicht das Ziel ist.

Options: ReplyQuote


Subject
Views
Written By
Posted
Problem mit SUBSELECT
6887
November 24, 2008 02:18AM
3155
November 24, 2008 08:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.