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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:43:59+00:00 2026-05-20T18:43:59+00:00

I use PHP, MySQL and Zend Framework. I have some simple tables with simple

  • 0

I use PHP, MySQL and Zend Framework. I have some simple tables with simple relations.

post_category - post (1:1)
post - post_comments (1:M)

I need to select last post with comments using 1 query. It is my query for getting all posts:

$select = $this->select()
->setIntegrityCheck(false)
->from(array('p' => 'post'))
->join(array('pc' => 'post_category'), 'pc.id = p.category_id',
   array('category_name' => 'name', 'category_name_key' => 'name_key'))
->joinLeft('post_comment', 'p.id = post_comment.post_id',
   array('comment_id' => 'id', 'created_by', 'comment', 'comment_date_creation' => 'date_creation'))
->order('p.date_creation desc');

I can not add ->limit(1) cause query can returns more than one row. How can I avoid this situation? I not want to create 2 queries.

Thank you in advance.

  • 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-05-20T18:44:00+00:00Added an answer on May 20, 2026 at 6:44 pm

    I may be reading this wrong, but if I am understanding you correctly you want to get the post and its comments but limit it to the most recent post…

    if thats the case why not add a WHERE clause and a subquery first…p.id = (SELECT Max(id) from post)

    In theory this should filter it to the latest post entered. The other option is to select on the max datetime if there is such a field.

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

Sidebar

Related Questions

I am working on a project using zend framework, php, mysql on ubuntu. I
I use MySQL in a fairly complex web site (PHP driven). Ideally, there would
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
Hope here are some with more knowledge about Zend Framework than me, I've been
I'm new to PHP and I recently started learning Zend Framework. What DAL are
I am trying to add some administration scripts to a Zend Framework project, that
Anyone know of a FREE and easy to use PHP MySQL Datagrid class? I
I want to use PHP and MySQL to insert data into a data table
I am working on a web portal (PHP/MYSQL) which have 3 sections photos, videos,
Is it possible to use PHP's SimpleXML functions to create an XML object from

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.