Question

I am currently trying to get the pagination working on data from multiple tables. Following the the code

$query = $this
                ->db
                ->select('group.*')
                ->select('group_type.GroupType')
                ->from ('group','group_type')
                ->join('group_type', 'group.GroupTypeId = group_type.GroupTypeId')
                //->where('group.UserId',$userid)
                ->get('group',$config['per_page'], $this->uri->segment(3))->result();

when this is run i get following error

    Error Number: 1066

Not unique table/alias: 'group'

SELECT `group`.*, `group_type`.`GroupType` FROM (`group`, `group`) JOIN `group_type` ON `group`.`GroupTypeId` = `group_type`.`GroupTypeId` LIMIT 10

i know the SQL query being generated here by CI is not correct. Need to know how to correct it?

Was it helpful?

Solution

Read the docs more carefully - you'll see that:

1) don't use two tables in your from()

2) don't use a from() and get() together in the way you are doing

OTHER TIPS

jmadsen's answer is correct,

To be specific, simply remove the

->from ('group','group_type')

Line.

You have already mentioned these two table names in your "join" and "get" parts of the query, that's why you do not need the "from" part.

The from part is causing this part of the SQL to be formed wrongly:

FROM (`group`, `group`)

Table names can't be repeated in FROM

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top