How to join tables?

There are few things you should remember when you’re using SQL in WordPress. The most important, I guess, would be table prefix. So your query should look something like this: global $wpdb; $sql = “SELECT kategorie.id, ogloszenia.kategoria, klient_id “. “FROM {$wpdb->prefix}category kategorie “. “JOIN {$wpdb->prefix}ogloszenia_kupione ogloszenia ON (ogloszenia.id = kategorie.id)”; $results = $wpdb->get_results( $sql );