Analog category_and (WP) in sql query

Thanks Milo for the answer! This block of code selects posts that have two categories at the same time.

( ( SELECT COUNT(1) FROM wp_term_relationships 
WHERE term_taxonomy_id IN (35,33) AND object_id = wp_posts.ID ) = 2 ) 

Where 35,33 are categories IDs and 2 – number of categories.