Hey there! any question in your mind? Ask It Now!.

Popular Categories





how to use multiple JOINS in cake php?

+4 votes
1,240 views
asked in Programming by amit_pammu Expert (5,030 points)
edited by Bhartesh
how to use multiple JOINS in cake php?

1 Answer

+2 votes
answered by krish Expert (6,310 points)

An SQL JOIN clause is used to combine rows from two or more tables, based on a common field between them.

Some of jines are following :

SQL Inner Join

SQL Left Join

SQL Right Join

SQL Full Join

SQL Union

This is a eg of join:

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;

Notice that the "CustomerID" column in the "Orders" table refers to the customer in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.

commented by amit_pammu Expert (5,030 points)
tell me how to use the third table..!!!
as per as the cake php syntax!!
commented by krish Expert (6,310 points)
If we talk about simple inner join of three tables so you can use this :

select * from tableA a
    inner join
    tableB b
    on a.common = b.common
    inner join
    TableC c
    on b.common = c.common

And for cake php i am giving you code see it you will get the point :
$this->bindModel(array(
        'belongsTo' => array(
            'Contact' => array(
                'className' => 'Contact',
                'foreignKey' => false,
                'conditions' => array(
                    'Message.user_id = Contact.user_id',
                    '`Message`.`mobileNo` IN (`Contact`.`mobileNo`,`Contact`.`workNo`,`Contact`.`homeNo`,`Contact`.`other`)'),
                'order'=>'Message.idTextMessage DESC',
            )
        )
    ), false);
    return $this->find('all', array('conditions' => array('Message.User_id' => $userid),
        'contain' => array('Contact' ),
        'fields' => array('Message.mobileNo',
            'Contact.mobileNo',
            'Contact.workNo',
            'Contact.homeNo',
            'Contact.other',
            'Contact.name',
            'Message.dateTime',
            'Message.type',
            'Message.body'),
        'group' => 'Message.mobileNo',
        'limit' => 6));
}

Related Questions

+6 votes
2 answers 1,999 views
+2 votes
1 answer 227 views
+2 votes
1 answer 176 views
+6 votes
3 answers 7,421 views
+1 vote
1 answer 306 views
+1 vote
1 answer 1,398 views
–1 vote
0 answers 192 views

Not a Member yet?

Ask to Folks Login

My Account
326 Folks are online
0 members and 326 guest online
Your feedback is highly appreciated