This SQL code retrieves a list of distinct categories and...

March 28, 2023 at 11:44 PM

SELECT DISTINCT ca.external_id as id, IF(ca.id = 63, 'otros', LOWER(ca.name)) as category_name FROM yapp_pap.product_new_releases pr INNER JOIN yapp.tb_product p ON (pr.product_id = p.id) INNER JOIN yapp.tb_laboratory l ON(p.laboratory_id = l.id) LEFT JOIN yapp.tb_product_category pc ON (p.id=pc.product_id AND pc.`status`=1) LEFT JOIN yapp.tb_category ca ON (pc.category_id=ca.id) WHERE pr.active=1 AND ca.id IS NOT null ORDER BY category_name; END$$ DELIMITER ;

This SQL code retrieves a list of distinct categories and their corresponding external IDs for active new product releases in a database. The categories are joined with the products they belong to, as well as the laboratory that produces them.

The IF statement is used to assign the name "otros" (which means "other" in Spanish) to category ID 63, otherwise it returns the lowercase version of the category name.

The results are sorted by the category name in ascending order. The code also sets the delimiter to "$$" at the end.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node