CodeIgniter Forums

Full Version: Query from multiple tables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi All,

I am a beginner in codeigniter. Could you please help me.

I want to return result from two tables.

The table structures are as given below.

1) user :   id     int(11), username varchar(16),status tinyint(1)
2) transaction : id int(11), tranType varchar(20),status tinyint(1) ,userid int(11)

Here relation between user and transaction table is one to many and I want to show the max record from transaction table grouping by

for example

user table has the following records

Quote:ID userName status
1 John 1
2 James 1

transaction table has the following records

Quote:Id TranType Status userID
1 signup 1 1
2 payment 1 1
3 approved 1 1

so here it should return the result as follow
Quote:user.ID userName,TranType userStatus Tran Status
1 John approved 1 1

How can I write a query for codeigniter joining the both tables and return the result with specific columns.

Many appreciation for you quick reply


El Forum

$query = "SELECT * FROM tbl1 LEFT JOIN tbl2 ".
"ON tbl1.ID = tbl2.ID WHERE = 1"


try not sure.but i hope it helps.

Big Grin