kadour Hk
kadour Hk

Reputation: 47

Error "unique table/alias" when joining 2 tables

I want to print items from table items by the Id_item found in the table favorites_items. I'm using the Codeigniter framework.

the error:

Not unique table/alias: 'favorites_items'

SELECT favorites_items., items. FROM favorites_items JOIN favorites_items ON id_item = items.id_ad

Code:

$this->db->select('favorites_items.*,items.*');
$this->db->from('favorites_items');
$this->db->join('favorites_items', 'id_item = items.id_ad');
$query = $this->db->get();
return $query->result_array();

Upvotes: 1

Views: 49

Answers (1)

Vickel
Vickel

Reputation: 7997

you don't join the table items, you join the table favorites_items to the table favorites_items

the correct way would be like:

$this->db->select('favorites_items.*,items.*');
$this->db->from('favorites_items');
$this->db->join('items', 'favorites_items.id_item = items.id_ad');
$query = $this->db->get();
return $query->result_array();

Upvotes: 1

Related Questions