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 9070915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:47:50+00:00 2026-06-16T17:47:50+00:00

I have the following mysql tables: CREATE TABLE Articles ( ArticleID SMALLINT NOT NULL

  • 0

I have the following mysql tables:

CREATE TABLE Articles (
   ArticleID SMALLINT NOT NULL PRIMARY KEY,
   ArticleTitle VARCHAR(60) NOT NULL,
   Copyright YEAR NOT NULL
)
ENGINE=INNODB;


INSERT INTO Articles VALUES (12786, 'How write a paper', 1934),
                            (13331, 'Publish a paper', 1919),
                            (14356, 'Sell a paper', 1966),
                            (15729, 'Buy a paper', 1932),
                            (16284, 'Conferences', 1996),
                            (17695, 'Journal', 1980),
                            (19264, 'Information', 1992),
                            (19354, 'AI', 1993);


CREATE TABLE Authors (
   AuthID SMALLINT NOT NULL PRIMARY KEY,
   AuthorFirstName VARCHAR(20),
   AuthorMiddleName VARCHAR(20),
   AuthorLastName VARCHAR(20)
)
ENGINE=INNODB;


INSERT INTO Authors VALUES (1006, 'Henry', 'S.', 'Thompson'),
                           (1007, 'Jason', 'Carol', 'Oak'),
                           (1008, 'James', NULL, 'Elk'),
                           (1009, 'Tom', 'M', 'Ride'),
                           (1010, 'Jack', 'K', 'Ken'),
                           (1011, 'Mary', 'G.', 'Lee'),
                           (1012, 'Annie', NULL, 'Peng'),
                           (1013, 'Alan', NULL, 'Wang'),
                           (1014, 'Nelson', NULL, 'Yin');


CREATE TABLE AuthorArticle (
   AuthID SMALLINT NOT NULL,
   ArticleID SMALLINT NOT NULL,
   PRIMARY KEY (AuthID, ArticleID),
   FOREIGN KEY (AuthID) REFERENCES Authors (AuthID),
   FOREIGN KEY (ArticleID) REFERENCES Articles (ArticleID)
)
ENGINE=INNODB;


INSERT INTO AuthorArticle VALUES (1006, 14356), 
                              (1008, 15729), 
                              (1009, 12786), 
                              (1010, 17695),
                              (1011, 15729), 
                              (1012, 19264), 
                              (1012, 19354), 
                              (1014, 16284);

Now I want to run a query to fetch data from all of the three tables. My query is as follows:

SELECT ArticleTitle, Copyright, CONCAT_WS(' ', AuthorFirstName, AuthorMiddleName, AuthorLastName) AS Author
FROM Articles AS b STRAIGHT_JOIN AuthorArticle AS ab STRAIGHT_JOIN Authors AS a
WHERE b.ArticleID=ab.ArticleID AND ab.AuthID=a.AuthID AND Copyright<1980
ORDER BY ArticleTitle;

So my question is how this will be accomplish in CakePHP 2+. Any help is appreciated…

  • 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-16T17:47:51+00:00Added an answer on June 16, 2026 at 5:47 pm

    I am able to answer to my own question but up to some extent i.e. joining multiple tables but not able to join with ‘STRAIGHT_JOIN’. So my solution is as under:

    $art = $this->Article->find('all', array('joins' => array(
        array(
            'table' => 'authorarticle',
            'alias' => 'AuthArt',
            'type' => 'inner',
            'foreignKey' => false,
            'conditions'=> array('AuthArt.ArticleID = Article.ArticleID')
        ),
        array(
            'table' => 'authors',
            'alias' => 'Author',
            'type' => 'inner',
            'foreignKey' => false,
            'conditions'=> array('AuthArt.AuthID = Author.AuthID')
            )
        ), 'fields'=>array('Article.ArticleTitle','CONCAT_WS(" ", Author.AuthorFirstName, Author.AuthorMiddleName, Author.AuthorLastName) As AuthorName','Article.Copyright'), 'conditions' => array('Article.Copyright' => 1980)));
    $this->set('articles', $art); // debug($articles) in the view to get results
    

    Hope it would help someone else looking for the same. I would like to hear from community if my own solution to my own question is good or it can be further optimized for getting best result in CAKEPHP way. Thanks

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

Sidebar

Related Questions

I have the following tables: CREATE TABLE `OBL2`.`item` ( `itemID` INT NOT NULL AUTO_INCREMENT
I have the following mysql tables: CREATE TABLE `video` ( `video_id` int(11) unsigned NOT
I have the following MySQL tables: CREATE TABLE IF NOT EXISTS `conversations` ( `id`
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
I have following tables in MySQL.(I am using php/mysql) CREATE TABLE `hw_subjects` ( `id`
Assume the following in MySQL: CREATE TABLE users ( id integer auto_increment primary key,
I have two tables as follows: CREATE TABLE customer ( id INT NOT NULL
I have the following tables CREATE TABLE IF NOT EXISTS `user` ( `id` int(11)
I have the following tables: create temporary table Items (item_id int, item_name varchar(10)); create
I have two mysql tables: /* Table users */ CREATE TABLE IF NOT EXISTS

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.