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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:36:16+00:00 2026-05-28T14:36:16+00:00

I have a multi-table SQL query. My need is: The query should I generate

  • 0

I have a multi-table SQL query.

My need is: The query should I generate a single line by ‘etablissement_id’ … and all information that I want to be back in the same query.

The problem is that this query is currently on a table where “establishment” may have “multiple photos” and suddenly, my query I currently generates several lines for the same id…

I want the following statement – LEFT JOINetablissementContenuMultimediaON etablissement.etablissement_id = etablissementContenuMultimedia.etablissementContenuMultimedia_etablissementId – only a single multimedia content is displayed. Is it possible to do this in the query below?

Here is the generated query.

SELECT DISTINCT `etablissement`. * , `etablissementContenuMultimedia`. * , `misEnAvant`. * , `quartier`. *
FROM `etablissement`
LEFT JOIN `etablissementContenuMultimedia` ON etablissement.etablissement_id = etablissementContenuMultimedia.etablissementContenuMultimedia_etablissementId
LEFT JOIN `misEnAvant` ON misEnAvant.misEnAvant_etablissementId = etablissement.etablissement_id
LEFT JOIN `quartier` ON quartier_id = etablissement_quartierId
WHERE (
    misEnAvant_typeMisEnAvantId =1
    AND (
        misEnAvant_dateDebut <= CURRENT_DATE
        AND CURRENT_DATE <= misEnAvant_dateFin
    )
)
AND (
    etablissement_isActive =1
)
ORDER BY `etablissement`.`etablissement_id` ASC
LIMIT 0 , 30

Here is the code used ZF

public function find (){
    $db = Zend_Db_Table::getDefaultAdapter();
    $oSelect = $db->select();
    $oSelect->distinct()
            ->from('etablissement')
            ->joinLeft('etablissementContenuMultimedia', 'etablissement.etablissement_id = etablissementContenuMultimedia.etablissementContenuMultimedia_etablissementId')
            ->joinLeft('misEnAvant', 'misEnAvant.misEnAvant_etablissementId = etablissement.etablissement_id')
            ->joinLeft('quartier', 'quartier_id = etablissement_quartierId ')
            ->where ('misEnAvant_typeMisEnAvantId = 1 AND (misEnAvant_dateDebut <= CURRENT_DATE AND CURRENT_DATE <= misEnAvant_dateFin) ')
            ->where ('etablissement_isActive = 1')
            ->order(new Zend_Db_Expr('RAND()'));


    $zSql = $oSelect->__toString();

    if(isset($_GET['debug']) AND $_GET['debug'] == 1)
        echo $zSql ;
    //die();

    $oResultEtablissement = $db->fetchAll($oSelect);   

    return $oResultEtablissement ;
}

Can you help me?

Sincerely,

  • 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-28T14:36:18+00:00Added an answer on May 28, 2026 at 2:36 pm

    I took the time to redo the whole model of the database … and now it works. There was no solution for a system as flawed

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

Sidebar

Related Questions

I have a multi-line string that I want to do an operation on each
I need to get the last inserted id of table that have multi-column primary
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
I have a multi-row insert that looks something like: insert into table VALUES (1,
I have created a multi column datastore on a table that allows me to
I have a large table with a multi-part index. I need to run several
I have a multi-user ASP.NET app running against SQL Server and want to have
I have a multi-timezone web application that stores all of the datetime values in
I have a situation where a certain linq query that runs against a multi-million
I want to run a SQL query to copy a row from my table

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.