Home > Archive > MySQL Server Forum > December 2005 > How to make a select statement FROM A TABLE that has two INDEXES









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to make a select statement FROM A TABLE that has two INDEXES
Angelos

2005-12-20, 9:23 am

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.
Gordon Burditt

2005-12-20, 9:23 am

>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 ?


You can join a table to itself (many times, if necessary).
Use an alias name for each instance of the table.

SELECT a.*, b.* FROM tablename a, tablename b
WHERE a.id = b.parentId

Gordon L. Burditt
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com