Atul Sachan Atul Sachan - 1 year ago 67
SQL Question

MYSQL Query. Please help me understand

Can someone please help me understand the below query, I am fairly new to SQL.

SELECT Count(*) FROM tblservicesubroutes ts
INNER JOIN tblservicelegs sl ON sl.serviceid = ts.serviceid
AND sl.fromcityid = ts.fromcityid AND sl.tocityid = ts.tocityid

Answer Source

This query finds the number of rows in the resultant table obtained after joining two tables tblservicesubroutes and tblservicelegs based on three columns common to both tables, which are serviceid,fromcityid,tocityid

In simple terms it finds the number of rows from both tables where there is a match between the columns specified after ON.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download