join with row having max value mysql code example Example: sql query to get the number of rows in a table SELECT COUNT(*) FROM tablename