Sql query :)

Hi and Hello :slight_smile: is anyone know on you can I construct a query for this?

student_subjects
15-01785 , Test
15-01785 , Test1
15-01785 , Test2
15-01785 , Test3
15-01785 , Test4
15-01786 , Test
15-01786 , Test1
15-01786 , Test2
15-01786 , Test3
15-01786 , Test4
this is my record in the database :frowning: … I try to spend many days for finding a solution for this :frowning: … please help me

I know comma separated values is a bad practice but this table is a temporary for uploading a CSV data

I don’t… understand what you’re asking for a query to do, exactly?

I want to make an query that results like this but i don’t have any idea .
15-01785 , Test
15-01785 , Test1
15-01785 , Test2
15-01785 , Test3
15-01785 , Test4
15-01786 , Test
15-01786 , Test1
15-01786 , Test2
15-01786 , Test3
15-01786 , Test4
:frowning:

Well it’s going to be a lot cleaner to just query the entire string and then split it.

how can i use split ? there’s no aggregate function for split in mysql

Yes, hence the link. Query the string as-is, and then use PHP to split the string instead.

:frowning: … My concern is about the 30 execution error … if I try to process it in PHP there will be an error :frowning: .

What sort of error?

And now you know the reason why.
If you want to do this all in the sql query, without post-processing the data in php, a better database design is the answer.

If you don’t want to solve it in PHP, why did you post the question in the PHP section of the forum?

(Sorry if that sounds grumpy, I don’t intend it to be. But you’re asking PHP developers how they’d get around the flaws in the database layout).

1 Like

It’s actually a valid point.

Does the OP want this moved to the Database forum?

I assume that since this is a temporary table, then the real tables you want to insert this into is normalized. I.e. the student is linked by a linking table to the subjects. Then the subjects are linked towards the departments, and also linked towards the instructors.

What you need to do is clean the data using PHP and then insert it properly. I.e. pull the data, then use explode on the strings to create the arrays, then match them properly when inserting into the tables (i.e. subject[0] would be tied to department[0] etc. or at least that is how it looks.)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.