Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82364

different sql result sets

$
0
0

When I run this server script (php) I get a result set having a size of 2,970 rows.

<?php

/*
 * Editor server script for DB table accounts
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'accounts', 'id' )
        ->fields(
                Field::inst( 'accounts.name' ),
                Field::inst( 'LENGTH( accounts.name) AS accounts.name_length' ),
                Field::inst( 'crm_sites.name' ),
                Field::inst( 'LENGTH( crm_sites.name) AS crm_sites.name_length' )
        )
        ->leftJoin( 'accounts_cstm', 'accounts.id', '=', 'accounts_cstm.id_c' )
        ->leftJoin( 'crm_sites_accounts_1_c', 'accounts.id', '=', 'crm_sites_accounts_1_c.crm_sites_accounts_1accounts_idb' )
        ->leftJoin( 'crm_sites', 'crm_sites.id', '=', 'crm_sites_accounts_1_c.crm_sites_accounts_1crm_sites_ida' )
        ->where( 'accounts.name', 'crm_sites.name', '!=', false )
        ->where( 'accounts.deleted', 0, '=' )
        ->where( 'crm_sites.deleted', 0, '=' )
        ->where( 'crm_sites_accounts_1_c.deleted', 0, '=' )
        ->debug( true )
        ->process( $_POST )
        ->json();

The sql query and bindings generated by the Editor are:

0   {…}
query   SELECT `accounts`.`id` as 'accounts.id', `accounts`.`name` as 'accounts.name', LENGTH( accounts.name) as 'LENGTH( accounts.name)', `crm_sites`.`name` as 'crm_sites.name', LENGTH( crm_sites.name) as 'LENGTH( crm_sites.name)' FROM `accounts` LEFT JOIN `accounts_cstm` ON `accounts`.`id` = `accounts_cstm`.`id_c` LEFT JOIN `crm_sites_accounts_1_c` ON `accounts`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1accounts_idb` LEFT JOIN `crm_sites` ON `crm_sites`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1crm_sites_ida` WHERE `accounts`.`name` != :where_0 AND `accounts`.`deleted` = :where_1 AND `crm_sites`.`deleted` = :where_2 AND `crm_sites_accounts_1_c`.`deleted` = :where_3
bindings    […]
0   
name    :where_0
value   crm_sites.name
type    null
1   {…}
name    :where_1
value   0
type    null
2   {…}
name    :where_2
value   0
type    null
3   {…}
name    :where_3
value   0
type    null

When I copy the query and replace the :where_[0-3] with the appropriate values I get the following query:

SELECT `accounts`.`id` as 'accounts.id', `accounts`.`name` as 'accounts.name', LENGTH( accounts.name) as 'LENGTH( accounts.name)', `crm_sites`.`name` as 'crm_sites.name', LENGTH( crm_sites.name) as 'LENGTH( crm_sites.name)' FROM `accounts` LEFT JOIN `accounts_cstm` ON `accounts`.`id` = `accounts_cstm`.`id_c` LEFT JOIN `crm_sites_accounts_1_c` ON `accounts`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1accounts_idb` LEFT JOIN `crm_sites` ON `crm_sites`.`id` = `crm_sites_accounts_1_c`.`crm_sites_accounts_1crm_sites_ida` WHERE `accounts`.`name` != `crm_sites`.`name` AND `accounts`.`deleted` = 0 AND `crm_sites`.`deleted` = 0 AND `crm_sites_accounts_1_c`.`deleted` = 0 ;

When I run this I get a result set of 89 rows (what I was expecting).

What am I missing.

The query is joining two tables with a map table and is comparing the 'name' fields and should return only those that do not match.


Viewing all articles
Browse latest Browse all 82364

Trending Articles