[SQL]Fatal error in the query

Solved
Hello,
I must have an error (more or less significant) in my query, but as strange as it may seem, I can't find it...

I hope you can see it better than I can

Here is my problematic query:

 $reponse= $bdd->query( 'SELECT Titre,affiche,lien,Genre FROM FROM films WHERE coupdecoeur=1 UNION SELECT Titre,affiche,lien,Genre FROM sagas WHERE coupdecoeur=1 ORDER BY Titre'); while ($donnees = $reponse->fetch()) { ... 


Thank you in advance for your answers and thank you for reading!

Have a good day,

hharchi9.

Configuration: Windows 7 / Chrome 38.0.2125.104

1 answer

  • Votes
  • Date
  • Descending date
  1. Hello,

    You have two FROM in the first query.
    1. Oh yes indeed, thank you :)

      However, I only get the results from the first query and not those from the second...
    2. What do the two tables contain?

      It should be noted that UNION does not keep duplicates.
    3. The first table contains a list of movies and the second one a list of sagas

      There are no duplicates in both tables.
    4. It's strange, I created both tables with one record in each and it's working for me.

      I used this code:

      $response= $bdd->query( 'SELECT Titre,affiche,lien,Genre FROM films WHERE coupdecoeur=1 UNION SELECT Titre,affiche,lien,Genre FROM sagas WHERE coupdecoeur=1 ORDER BY Titre'); while ($data = $response->fetch()) { echo $data["Titre"] . " " . $data["affiche"] . " " . $data["lien"] . " " . $data["Genre"]; } ?>
    5. The problem may come from the fact that "sagas" has an extra column... Indeed, I only load a fraction of the columns from my tables.