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

Popular Categories





how to use multiple JOINS in cake php?

+4 votes
875 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,522 views
+3 votes
3 answers 2,427 views
+2 votes
1 answer 99 views
asked in Programming by krish Expert (6,310 points)
+2 votes
1 answer 136 views
+6 votes
3 answers 6,828 views
+6 votes
1 answer 236 views
+1 vote
1 answer 220 views
asked in Programming by duke Expert (5,813 points)
+1 vote
1 answer 950 views
–1 vote
0 answers 111 views
+4 votes
5 answers 713 views

Not a Member yet?

Ask to Folks Login

My Account
870 Folks are online
82 members and 788 guest online
Your feedback is highly appreciated