of course you can
SELECT a1.id, a1.item, (SELECT corners from table2 where item_id = a1.id limit 0, 1) as round, (SELECT corners from table2 where item_id = a1.id limit 1, 1) as cube from( SELECT id, item from table1 ) as a1
So it will be displayed, but why do you need it?
Isn't it better to choose the data as it is and just manipulate it when displaying it? (ie, the data was selected with the help of JOIN and when you process it you enter it into an array and that's it ... you have data ready for work)
On the client, you can also manipulate the data, as described above, but then there’s a question (why choose data from the database that is not needed?), If your data on the client will often need to display some other dynamically, then not to make a selection from the database here and there ... maybe it makes sense to choose a bunch and already on the client to discard it, if such a task does not provide for that, I wouldn’t do it on the client.
join
. But where is the guarantee that there will always be only two fields? You can slightly alter the result - in one column the list ofshape
, in another column - the list ofcorners
. This can be done viaGROUP_CONCAT
And you will separate them programmatically. - BOPOHitem_id
will have two entries, the other will have three, and the tenth will have all ten. Although if oneitem_id
guaranteed to have only two entries, then I think you can do it throughjoin
. - BOPOHround
, for the second andround
andcube
, and for the third there will not be any, and for the fourth there will be 3 columns that are not similar to the previous ones and etc. - igolka97corners
throughGROUP_CONCAT
in one field, a list ofcorners
in another field ( example ), and in php from these fields generate the result you need through explode . True, the result here is not always desired . Easier on the client (php) to collect everything - BOPOH