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

Popular Categories





how to use multiple JOINS in cake php?

+4 votes
1,058 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,680 views
+3 votes
3 answers 2,654 views
+2 votes
1 answer 137 views
asked in Programming by krish Expert (6,310 points)
+2 votes
1 answer 155 views
+6 votes
3 answers 7,052 views
+6 votes
1 answer 263 views
+1 vote
1 answer 249 views
asked in Programming by duke Expert (5,813 points)
+1 vote
1 answer 1,127 views
–1 vote
0 answers 153 views
+4 votes
5 answers 770 views

Not a Member yet?

Ask to Folks Login

My Account
675 Folks are online
5 members and 670 guest online
Your feedback is highly appreciated