U
U
Urukhayy2015-12-18 13:36:02
MySQL
Urukhayy, 2015-12-18 13:36:02

How to make such a request?

Contained in the table:

profile_id          car_id
1                      4
1                     14
1                     21

The query result should be:
profile_id      car_one       car_two      car_three
1                    4           14           21

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
Boris Benkovsky, 2015-12-18
@benbor

Even if you write such a request, I'm sure the people who will maintain your code will hate you, your relatives, and so on.
DB for storing data, and for optimal, fast selections.
And already, please, wrap the display logic in the Server Programming Language. This will take 3 lines of code.
PS Of course, I'm talking about code that should reach production someday. If this task is for educational purposes, then good luck)

M
Max, 2015-12-18
@MaxDukov

IMHO You will need a separate table for this with
car_name car_id
car_one 4
car_two 14 then
join and pivot

F
Fellowship, 2015-12-18
@Fellowship

I advise you to take a closer look at this link - forums.mysql.com/read.php?20,75357,75357#msg-75357

J
Justique, 2015-12-18
@Justique

SELECT profile_id, GROUP_CONCAT(car_id separator ';') as cars FROM `table` GROUP BY profile_id

Then explode and that's it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question