Alasql - querying nested objects in json
<p>I have a json object like below.</p>

<p>Ebay Object</p>

<pre><code>    {
    __v: 0
    _id: "56e192f0aea7131c15513328"
    headquarters: "New York"
    name: "Ebay"
    productCategories: [{
        _id: "56e193beaea7131c1551332d"
        name: "Footwear"
        products: [{
            name: 'Shiela',
            price: 420,
            totalSales: [10, 20]
        }, {
            name: 'Parry',
            price: 350,
            totalSales: [50, 20]
        }]
        totalSales: 100
    }, {
        1: Object
        _id: "56e193beaea7131c1551332e"
        name: "Clothes"
        products: [{
            name: 'Kurta',
            price: 210,
            totalSales: [60, 80]
        }, {
            name: 'Sun Glass',
            price: 785,
            totalSales: [5, 25]
        }],
        totalSales: 170
    }]
}
</code></pre>

<p>Amazon Object</p>

<pre><code>{
        __v: 0
        _id: "56e192f0aea7131c15513328"
        headquarters: "New York"
        name: "Amazon"
        productCategories: [{
            _id: "56e193beaea7131c1551332d"
            name: "Footwear"
            products: [{
                name: 'Shiela',
                price: 280,
                totalSales: [10, 20]
            }, {
                name: 'Parry',
                price: 785,
                totalSales: [50, 20]
            }]
            totalSales: 100
        }, {
            1: Object
            _id: "56e193beaea7131c1551332e"
            name: "Clothes"
            products: [{
                name: 'Kurta',
                price: 150,
                totalSales: [60, 80]
            }, {
                name: 'Sun Glass',
                price: 485,
                totalSales: [5, 25]
            }],
            totalSales: 170
        }]
    }
</code></pre>

<p>I want to select each name inside product categories, that are common to both the companies.</p>

<p>Then, I want to select the products that are common to the common product categories.</p>

<p>Then I want to get the price of the common products (to both the companies) for comparison</p>

<p>I am able to run the below query</p>

<pre><code> alasql('SELECT products FROM ? AS CATEGORY1 JOIN ? AS CATEGORY2 USING [0]', [$scope.company1.productCategories, $scope.company2.productCategories], function(data) {
                    console.log("join query executed");
                    console.log(data);
                });
</code></pre>

<p>I want to find the products inside each product category. I want a query like</p>

<pre><code>alasql('SELECT products.name,products.price FROM ? as category1 join ? as category2 using products.name', [$scope.company1.productcategories,$scope.company2.productcategories], function(data) {
                    console.log("Query executed");
                    console.log(data);
                });
</code></pre>

<p>But this errors out.</p>

<p>Please let me know the correct procedure.</p>

<p>Regards,
Sabarisri</p>