Convert a WP Query into a simpler SQL query to fetch only COUNT of posts

You can also try below code to retrieve count of rows.

$myquery = $wpdb->get_results( "SELECT * FROM  tablename WHERE ID='some-value'" );
echo  $wpdb->num_rows;

Let me know if you have any problem.

cheers

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)