skip to Main Content

I need to modify MySQL code to pass this error and get the same result.


I use localhost with Xampp ..

  • Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.1
  • Server type: MariaDB
  • Server version: 10.1.30-MariaDB – mariadb.org binary distribution
  • Database client version: libmysql – mysqlnd 5.0.12-dev – 20150407
  • PhpMyAdmin Version information: 4.7.4, latest stable version: 4.9.1
CREATE VIEW product_variation_stock_view AS
                SELECT 
                    product_variations.product_id AS product_id,
                    product_variations.id AS product_variation_id,
                    COALESCE(SUM(stocks.quantity) - COALESCE(SUM(product_variation_order.quantity), 0), 0) AS stock,
                    CASE WHEN COALESCE(SUM(stocks.quantity) - COALESCE(SUM(product_variation_order.quantity), 0), 0) > 0
                        THEN true
                        ELSE false
                    END in_stock
                FROM product_variations
                LEFT JOIN(
                    SELECT stocks.product_variation_id AS id,
                    SUM(stocks.quantity) AS quantity
                    FROM stocks
                    GROUP BY stocks.product_variation_id
                ) AS stocks USING (id)
                LEFT JOIN (
                    SELECT
                        product_variation_order.product_variation_id AS id,
                        SUM(product_variation_order.quantity) AS quantity
                    FROM product_variation_order
                    GROUP BY product_variation_order.product_variation_id
                ) AS product_variation_order USING (id)
                GROUP BY product_variations.id

MySQL said:

#1349 – View’s SELECT contains a subquery in the FROM clause

2

Answers


  1. Chosen as BEST ANSWER

    upgrade to mysql-8 and my problem is solved.


    To Upgrade MySql included in XAMPP (I did it on a Windows system):

    1. Rename your Mysql directory to some other name.
    2. Download the .msi file from the MariaDB link https://downloads.mariadb.org/.
    3. Run .msi. Change the install directory to your Mysql location under XAMPP.
    4. After completion, copy the old my.ini from the original mysql/bin directory to your new mysql/bin directory.
    5. You should be able to start Mysql from the XAMPP control panel.

    I found the solution here http://www.mynotebucket.com/update-mysql-under-xmpp/


  2. You need to upgrade your MySQL. If for any reason you are unable to do so, you can create views for the subqueries and integrate them into your query.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search