Hey everyone!

With the holiday season upon us, we want to share our upcoming working hours:

After that, we’ll return to our regular schedule and assist you as quickly as possible.

In the meantime, you can explore our documentation for Amelia and wpDataTables. You'll find tons of helpful resources, including articles and handy video tutorials on YouTube (Amelia's YouTube Channel and wpDataTables' YouTube Channel), which might just have the answers you need while we’re away.

Thanks a bunch for your understanding and support!

Warm regards and happy holidays!

TMS

Okay
  Public Ticket #2933427
SQL Query Error when I try to join different tables
Closed

Comments

  • Diego Sarmiento started the conversation

    I have a trouble in order to get the Table I want.  I try to join different tables in one which must give me the result of join and addition.

    The final table must give me the additions of each table, of the columns ¨Jueves, Viernes, Sabado, Lunes, Martes, Miercoles¨

    And for the "Semana" column, it must be the one that identifies the equality condition (not whether to use WHERE or AND). So if week "1" is in the 3 data tables, then I add the columns ¨Jueves, Viernes, Sabado, Lunes, Martes, Miercoles¨ respectively.

    1º Try, I use this query (It does not work):

    SELECT portal_wp_wpdatatable_1_1_1_1.`semana`,
           portal_wp_wpdatatable_1_1_1_1.`jueves`,
           portal_wp_wpdatatable_1_1_1_1.`viernes`,
           portal_wp_wpdatatable_1_1_1_1.`sabado`,
           portal_wp_wpdatatable_1_1_1_1.`lunes`,
           portal_wp_wpdatatable_1_1_1_1.`martes`,
           portal_wp_wpdatatable_1_1_1_1.`miercoles`,
           portal_wp_wpdatatable_5_1.`semana`,
           portal_wp_wpdatatable_5_1.`jueves`,
           portal_wp_wpdatatable_5_1.`viernes`,
           portal_wp_wpdatatable_5_1.`sabado`,
           portal_wp_wpdatatable_5_1.`lunes`,
           portal_wp_wpdatatable_5_1.`martes`,
           portal_wp_wpdatatable_5_1.`miercoles`,
           portal_wp_wpdatatable_8.`semana`,
           portal_wp_wpdatatable_8.`jueves`,
           portal_wp_wpdatatable_8.`viernes`,
           portal_wp_wpdatatable_8.`sabado`,
           portal_wp_wpdatatable_8.`lunes`,
           portal_wp_wpdatatable_8.`martes`,
           portal_wp_wpdatatable_8.`miercoles`
    FROM portal_wp_wpdatatable_1_1_1_1
      LEFT JOIN portal_wp_wpdatatable_5_1
         ON portal_wp_wpdatatable_1_1_1_1.`semana` = portal_wp_wpdatatable_5_1.`semana`
      LEFT JOIN portal_wp_wpdatatable_8
         ON portal_wp_wpdatatable_5_1.`semana` = portal_wp_wpdatatable_8.`semana`
      LEFT JOIN portal_wp_wpdatatable_1_1_1_1
         ON portal_wp_wpdatatable_8.`semana` = portal_wp_wpdatatable_1_1_1_1.`semana`

    GROUP BY portal_wp_wpdatatable_1_1_1_1.`semana`, portal_wp_wpdatatable_1_1_1_1.`jueves`, portal_wp_wpdatatable_1_1_1_1.`viernes`, portal_wp_wpdatatable_1_1_1_1.`sabado`, portal_wp_wpdatatable_1_1_1_1.`lunes`, portal_wp_wpdatatable_1_1_1_1.`martes`, portal_wp_wpdatatable_1_1_1_1.`miercoles`, portal_wp_wpdatatable_5_1.`semana`, portal_wp_wpdatatable_5_1.`jueves`, portal_wp_wpdatatable_5_1.`viernes`, portal_wp_wpdatatable_5_1.`sabado`, portal_wp_wpdatatable_5_1.`lunes`, portal_wp_wpdatatable_5_1.`martes`, portal_wp_wpdatatable_5_1.`miercoles`, portal_wp_wpdatatable_8.`semana`, portal_wp_wpdatatable_8.`jueves`, portal_wp_wpdatatable_8.`viernes`, portal_wp_wpdatatable_8.`sabado`, portal_wp_wpdatatable_8.`lunes`, portal_wp_wpdatatable_8.`martes`, portal_wp_wpdatatable_8.`miercoles`


    2º Try, I use this query (also It does not work):

    SELECT portal_wp_wpdatatable_1_1_1_1.`semana`,
           portal_wp_wpdatatable_1_1_1_1.`jueves`,
           portal_wp_wpdatatable_1_1_1_1.`viernes`,
           portal_wp_wpdatatable_1_1_1_1.`sabado`,
           portal_wp_wpdatatable_1_1_1_1.`lunes`,
           portal_wp_wpdatatable_1_1_1_1.`martes`,
           portal_wp_wpdatatable_1_1_1_1.`miercoles`
           FROM portal_wp_wpdatatable_1_1_1_1,portal_wp_wpdatatable_5_1,portal_wp_wpdatatable_8
      WHERE portal_wp_wpdatatable_1_1_1_1.semana = portal_wp_wpdatatable_5_1.semana
      AND portal_wp_wpdatatable_8.semana = portal_wp_wpdatatable_1_1_1_1.semana

      LEFT JOIN portal_wp_wpdatatable_5_1

         ON portal_wp_wpdatatable_1_1_1_1.semana = portal_wp_wpdatatable_5_1.semana

      LEFT JOIN portal_wp_wpdatatable_8

         ON portal_wp_wpdatatable_5_1.semana = portal_wp_wpdatatable_8.semana

      LEFT JOIN portal_wp_wpdatatable_1_1_1_1

         ON portal_wp_wpdatatable_8.semana = portal_wp_wpdatatable_1_1_1_1.semana


    Please I need help, to solve this.

  • [deleted] replied

    Hi Diego

    Thank you for reaching out to us.

    If your MySQL-query based wpDataTable doesn’t work, probably this is happening because wpDataTables server has problems with parsing of the query and building new queries dynamically (rarely happens, but does sometimes). To avoid this please prepare a MySQL view (a stored query), which will return the data that you need, call it e.g. “view1” and then build a wpDataTabled based on a simple query like “SELECT * FROM view1″.

    Please note some this when working with the server-side processing feature:

    • Please do not use “LIMIT” in the SELECT statement. wpDataTables adds it automatically and it will be overridden.
    • Please do not use “ORDER BY” in the SELECT statement. wpDataTables has its own sorting engine so it makes no sense to use MySQL’s sorting, since it will be overridden. Also, server-side processing feature adds this part of statement automatically when users trigger the sorting on the front-end, and having it in initial statement may cause the table to crash.

    I hope this helps, do let us know if you need any further assistance.