Quick note on CROSS JOIN

Quick note on CROSS JOIN

Example: If you want to retrieve a last row of information from a table, you could search for the max/highest row ID that has been created in that table to be sure that you are working against the latest one.

"SELECT tblOne.* FROM tblOne, (SELECT MAX(ID) as maxID FROM tblOne) maxresults WHERE tblOne.ID = maxresults.maxID"

It does not need to be the same table in the subquery. You can compare it against using a “table view” stored in the DBMS, it’s a good middle thing to use when you think the query is not quite big enough to be wanting to create a view for it.

It is not that often this method is needed, but there are times. When you need 2 subqueries in 1 query it’s called a CROSS JOIN.

Leave a Reply