|
Posted by Carl on 12/20/05 20:20
Angelos wrote:
> Hello,
> I have the folowing table:
> -----------
> | content |
> -----------
> |id |
> |parentId |
> |title |
> -----------
>
> I want to select all the table records but I want in the ParentColumn to
> return the title instead of the ID.
>
> If it was in two different tables I would doit using SELECT * FROM t1,t2
> WHERE t1.id = t2.parentId
>
> BUT they are in one table.
> Can anyone give me a hint ?
>
> I think it should be reallyt simple but I am stuck.
Definitely relevant in my opinion.
Try something like:
"SELECT a.id AS p_id, a.title AS p_title, b.id AS id, b.title AS title
FROM table a, table b
WHERE a.id = b.parent_id"
So basically you are joining the table back onto itself, and giving an
identifier to each (a & b). The fields in the parent record can be
accessed by the names (p_id, p_title).
Hope that helps.
Carl.
Navigation:
[Reply to this message]
|