CodeIgniter Forums

Full Version: Database error #1066
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
guys please help me with this error:

A Database Error Occurred
Error Number: 1066
Not unique table/alias: 'ms_sms'
SELECT *, `ms_tags`.`id` as `tag_ids` FROM `ms_sms` LEFT JOIN `ms_sms` ON `ms_sms`.`id` = `ms_tags_meta`.`sms_id` LEFT JOIN `ms_tags_meta` ON `ms_tags_meta`.`tag_id` = `ms_tags`.`id` GROUP BY `id` ORDER BY `id` DESC
Filename: controllers/me/do.php
Line Number: 70
and here is my code

        $this->db->select(' as tag_ids', ' as tag_names');
        $this->db->join('sms', ' = tags_meta.sms_id', 'left');
        $this->db->join('tags_meta', 'tags_meta.tag_id =', 'left');
        $this->db->order_by('id', 'DESC');

    //$sms = $this->db->get();
        $pages =  new Paginator(SETTING_SMS_PER_PAGE, 'page');
    $data['pageLinks'] = $pages->pageLinks();
        $data['smss'] = $this->db->get()->result();
What kind of help do you need? The error message says exactly what the problem is.
i don't know how to fix it. I don't have much knowledge in sql queries usage. So any guide on how to fix it?
You don't know enough SQL to fix a name conflict, but you're doing JOINs?

That query has more than one problem, it's not just the fatal error you're getting ... I can give you a cop-out answer that effectively hides the error message, but that won't be enough to fetch the correct result set.

In fact, I probably would've done just that, but I see identifiers named "sms" and such ... Dealing with mobile messages is not homework given by a school teacher, nor something to just play with. I urge you to put an effort into learning basic SQL before continuing your work.
this is not mobile network stuffs. Its a kinda typo of which is why i have a table called sms. Right now you are not helping. I am here to seek for solution or an approach of solution to my problem.
Narf is right you should work on your SQL skills before you carry on.

Your error is very basic you can not use the same table in a JOIN and a FROM clause unless you use an ALIAS.

change your join for

PHP Code:
$this->db->join('tags_meta'' = tags_meta.sms_id''left');
$this->db->join('tags''tags_meta.tag_id =''left'); 
@narf sorry about my behaviour.
@salain thanks for the help.
I thinks i will need to start learning sql basics.