I am following this tutorial on my installed version of MySQL, but it's throwing me an error:
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'MAX(IF(property_name = ''',
property_name,
''', value, NULL)) AS ',
property_name
)
) INTO @sql
FROM
properties;
SET @sql = CONCAT('SELECT item_id, ', @sql, ' FROM properties GROUP BY item_id');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
I am pasting it on SQL editor in phpMyAdmin.
I followed the suggestion. No errors shown but here's the result:
SELECT item_id
,MAX(IF(property_name = 'color', value, NULL)) AS color
,MAX(IF(property_name = 'size', value, NULL)) AS size
,MAX(IF(property_name = 'weight', value, NULL)) AS weight
FROM properties GROUP BY item_id
MySQL is a tool used to manage databases and servers, so while it's not a database, it's widely used in relation to managing and organising data in databases.
SQL is primarily used to query and operate database systems. MySQL allows you to handle, store, modify and delete data and store data in an organized way. SQL does not support any connector. MySQL comes with an in-built tool known as MySQL Workbench that facilitates creating, designing, and building databases.
MySQL is a database management system. It may be anything from a simple shopping list to a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server.
MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses.
If you have access to a MySQL command-line, I think you'll find your SQL code is fine (as long as @sql
doesn't equal NULL
) and the issue is with phpMyAdmin. Another idea is to wrap the code in a stored procedure and then CALL
the procedure.
You need to remove the DEALLOCATE PREPARE stmt;
from your query until after the query runs.
DEALLOCATE
cancels the statement before it has a chance to run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With