0

I have a problem when I want to fetch data from data base The problem lies in the use of(-) exemple (code-produit) With that I can not change anything in data base

Requet:

SELECT `Commande.numéro-Commande`,`Date`,`Code-Produit`,`Désignation`,`Prix-Unitaire`,`Qte` 
FROM `client`,`commande`,`produit`,`ligne-commande` 
WHERE `client.Code-client`=`commande.Code-client` and 
      `commande.Numèro-commande`=`ligne-commande.Numèro-commande` and
     `ligne-commande.Code_Produit`=`produit.Code-Produit` and 
     `code-client`=5

Error:

The mistake that gets

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
abdo
  • 1
  • 1

2 Answers2

1

If you want to use hyphen - in your table/column name(s), you should consider wrapping it using backticks. Otherwise, MySQL parser would read it as subtraction operator. My recommendation is to use underscore _ instead of hyphen -.

Secondly, please don't use Old comma based Implicit joins and use Modern Explicit Join based syntax

SELECT Commande.`numéro-Commande`,
       Date,
       `Code-Produit`,
       Désignation,
       `Prix-Unitaire`,
       Qte 
FROM client 
JOIN commande ON client.`Code-client` = commande.`Code-client`
JOIN produit ON `ligne-commande`.Code_Produit=produit.`Code-Produit`
JOIN `ligne-commande` ON commande.`Numèro-commande` = `ligne-commande`.`Numèro-commande`
WHERE client.`code-client` = 5
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
1

Set the table for the last code-client (code-client=5), it could be from client or commande, so set the table

Evgeni Enchev
  • 552
  • 3
  • 10