List:General Discussion« Previous MessageNext Message »
From:Tsubasa Tanaka Date:May 28 2012 9:25am
Subject:Re: category with parentid
View as plain text  
Hello Pesebe-san,

how about this?


SELECT
 t1.name AS cat,
 GROUP_CONCAT(t2.name) AS subcat
FROM table AS t1
LEFT JOIN table AS t2 ON t1.id = t2.parentid
WHERE t1.parentid = 0 GROUP BY cat;

+-------+-------------------+
| cat   | subcat            |
+-------+-------------------+
| cat A | subcat A,subcat A |
| cat B | subcat B          |
+-------+-------------------+
2 rows in set (0.00 sec)


regards,


ts. tanaka//

2012/5/28 HaidarPesebe <haidarpesebe@stripped>:
> Thanks for the information;
>
> I tried to call the database with something like this;
>
> select id,name from TABLE WHERE parentid='0'
>
> and a second call to the same table as this;
>
> select id,name from TABLE WHERE parentid='$id' (this $id is the result of
> calling the first call TABLE)
>
> and successfully.
> or are there other examples that simple?
>
> Thanks
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 7173 (20120527) __________
>
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql
>
Thread
category with parentidHaidarPesebe25 May
  • Re: category with parentidhsv25 May
    • Re: category with parentidAndrĂ©s Tello25 May
      • Re: category with parentidhsv26 May
    • Re: category with parentidPeter Brawley25 May
  • Re: category with parentidHaidarPesebe28 May
    • Re: category with parentidTsubasa Tanaka28 May
    • Re: category with parentidhsv28 May
    • Re: category with parentidhsv28 May
Re: category with parentidHaidarPesebe30 May
Re: category with parentidHaidarPesebe30 May
  • Re: category with parentidTsubasa Tanaka30 May