Maxime Pouliot
Maxime Pouliot

Reputation: 11

Can use Order By on view

I'm trying to order a view called listeModePays. Here's my view in SQL

SELECT
   paiementEtranger.pays.nomPays, 
   paiementEtranger.mode.pays,
   [... other columns ...]
   paiementEtranger.choixMode.hierarchie 
FROM            
   paiementEtranger.choixMode 
   INNER JOIN paiementEtranger.mode 
       ON paiementEtranger.choixMode.id = paiementEtranger.mode.mode 
   INNER JOIN paiementEtranger.pays 
       ON paiementEtranger.mode.pays = paiementEtranger.pays.id
WHERE
    (paiementEtranger.pays.supprime = 0) AND
    (paiementEtranger.mode.supprime = 0)

And then I'm trying to ORDER By a part of this view using this query

SELECT * FROM paiementEtranger.listeModePays 
WHERE pays="xxx" ORDER BY choixMode.hierarchie

When I add the ORDER BY choixMode.hierarchie in my query, I get a "multi-part identifier "choixMode.hierarchie" could not be bound" error. Anybody can help?

Upvotes: 0

Views: 60

Answers (1)

Jamiec
Jamiec

Reputation: 136134

Your question just shows a SELECT statement, but you describe it as a view - so assuuming the statement defined is a view, you simply do not need the table name - the view has a column called hierachie which is sourced from the choixMode table.

So, you simply want

SELECT * FROM paiementEtranger.listeModePays 
WHERE pays="xxx" 
ORDER BY hierarchie

Upvotes: 3

Related Questions