Skip to content
Advertisement

SQL (?) How to parse parent category from breadcrumb to update fields with parentIDs?

I have a bit of a tricky problem hoping someone can help me with.

I have a category structure that includes:

  • id
  • category path
  • category name

Example:

What I need is to identify the parent category for each row so the table would look something like this:

  • id
  • name
  • path
  • parent_id

The data is in SQL but I have text files as well and open to working on the command line to accomplish this. Maybe its a better tool for the job?

Here is an SQL fiddle using the query provided by below and the sample data above:

http://sqlfiddle.com/#!9/e060ec/1

Thanks in advance for any guidance.

Advertisement

Answer

I have correct the sql.

SQL Fiddle

I dont have enough reputation to add a comment,so I push a new answer.Sorry for that.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement