Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:28:13+00:00 2026-06-18T14:28:13+00:00

I recently started a project using Yii and I’m trying to get used to

  • 0

I recently started a project using Yii and I’m trying to get used to the query builder. Now, I want to make a query using joins and access the joining tables’ data in the query but I haven’t been able to get the following to work:

My (simplified) db-tables:

customer(#id, name)

employee(#id, name)

customer_employee(#customerid, #employeeid)

accounting(#id, customerid, started_date, finished_date, month, year)

  • many-to-many relation between customer and employee
  • one-to-many relation between customer and accounting

I want to execute the following query, which would select all the customers associated with a certain employee and display their accounting status (started_date & finished_date) if applicable (otherwise null).

The following query works perfectly, it’s just that I can’t get it to work with the cdbcriteria and Yii query builder: (also, hardcoded id is just for this example)

SELECT name, started_date, finished_date
FROM customer
RIGHT JOIN customer_employee ON customer.id=customer_employee.customerid
LEFT JOIN accounting ON customer.id=accounting.customerid
WHERE customer_employee.employeeid=2';

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:28:14+00:00Added an answer on June 18, 2026 at 2:28 pm

    1.
    createCommand

    Yii::app()->db->createCommand()
      ->select('name, started_date, finished_date')
      ->from('customer c')
      ->rightJoin('customer_employee ce', 'c.id=ce.customerid')
      ->leftJoin('accounting a', 'c.id=a.customerid')
      ->where('ce.employeeid=:id', array(':id'=>2))
      ->queryRow();
    

    2.
    CdbCriteria

    $criteria = new CDbCriteria;
    $criteria->select    = 'name, started_date, finished_date';
    $criteria->join      = 'RIGHT JOIN customer_employee ON customer.id=customer_employee.customerid ';
    $criteria->join     .= 'LEFT JOIN accounting ON customer.id=accounting.customerid';
    $criteria->condition = 'customer_employee.employeeid=:id';
    $criteria->params    = array(':id'=>2);
    
    $customers = Customers::model()->find($criteria);
    

    *.
    don’t forget the rules: http://www.yiiframework.com/doc/guide/1.1/en/database.arr

    I didn’t tested your SQLs, but if worked for you, these should, also work in Yii.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started work on a new project using PHP5 and want to use
Recently I started using codeplex.com for hosting a project I'm doing which I want
I have recently started using PlayN for a hobby project and has now stumbled
At work, we recently started a project using CouchDB (a document-oriented database). I've been
I have a recently started project where i'm using mongoid for the database and
I have recently started a project in Ruby on Rails. I used to do
I've recently started my new private project. The main goal which I want to
I started a demonstration project on HTML, JSON and jQuery recently. Thing I want
I recently started a project, using Apple's Utility Application example project. In the example
I recently started using Mac OS X for a flex/actionscript project and having a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.