Yii Framework Forum: Sql query error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sql query error Rate Topic: -----

#1 User is offline   sbondi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 07-October 10

Posted 03 December 2010 - 05:22 AM

Ciao,

sto eseguendo una query:

$minimo=Projects::model()->findAllBySql(
"SELECT MIN(nbofphase) as minimo FROM
(SELECT class_id,COUNT(ph_id) as nbofphase
FROM tbl_phases right join tbl_projects on (tbl_phases.project_id = tbl_projects.project_id)
WHERE (class_id=:classID)
group by class_id,tbl_phases.project_id)
"
,array(':classID'=>$class_id)

);

e ho un errore :
Syntax error or access violation: 1248 Every derived table must have its own alias

sapete come risolvere?
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 03 December 2010 - 05:31 AM

si', devi dare un alias alla tabella derivata:


SELECT MIN(nbofphase) as minimo FROM
(
   SELECT class_id,COUNT(ph_id) as nbofphase
   FROM tbl_phases right join tbl_projects on (tbl_phases.project_id = tbl_projects.project_id)
   WHERE (class_id=:classID)
   group by class_id,tbl_phases.project_id
) derivedTable1


O cosi' o con gli apici su 'derivedTable1'.

Prova e fammi sapere se risolve
-1

#3 User is offline   sbondi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 07-October 10

Posted 03 December 2010 - 05:35 AM

View Postzaccaria, on 03 December 2010 - 05:31 AM, said:

si', devi dare un alias alla tabella derivata:


SELECT MIN(nbofphase) as minimo FROM
(
   SELECT class_id,COUNT(ph_id) as nbofphase
   FROM tbl_phases right join tbl_projects on (tbl_phases.project_id = tbl_projects.project_id)
   WHERE (class_id=:classID)
   group by class_id,tbl_phases.project_id
) derivedTable1


O cosi' o con gli apici su 'derivedTable1'.

Prova e fammi sapere se risolve



ti confermo che funziona senza l'uso degli apici
ti ringrazio
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users