intersect api combine the result of two or more select query and take only common records between the queries result.

Use Case


There are times when one query is not able to fulfill the situation and so you need to use multiple query but now you are getting duplicate records. intersect api is useful in these situation where it combines the results of multiple select query and takes only common records between them.

e.g - Consider below queries -

1st query

connection.select({
    from: 'Products',
    where: {
        price: {
            '>': 10
        }
    }
})

2nd query

connection.select({
    from: 'Products',
    where: {
        price: {
            '>': 50
        }
    }
})

now in the above two queries - results from first query will have some records existing in results of 2nd query.

so using intersect we will take common results between two results and query will be -

var query1=  {
    from: 'Products',
    where: {
        price: {
            '>': 10
        }
    }
};
var query2 = {
    from: 'Products',
    where: {
        price: {
            '>': 50
        }
    }
};
var results = await connection.intersect({
    queries:[query1,query2]    
})

Example