2014-03-25 2 views
2

안녕하세요, 내 프로젝트에서 by 절의 mysql 쿼리에서 index 키워드를 사용해야한다는 요구 사항이 있습니다.mysql은 열 이름으로 인덱스 키워드를 사용합니다.

내 쿼리는 다음과 같습니다

 SELECT asset.id, day_part.category, asset.site_id, site.name, 
      environment.category_1, environment.category_2, county.town, county.county, 
      site.site_id as siteid, media_owner.contractor_name, 
      IF (audience_category.impact IS NULL, 0, audience_category.impact) as impact, 
      tv_region.id as tv_region_id, 
      metropolitan.id as metropolitan_id, 
      IF (
       price.price_site = -1, 
       IF(
        price.price_tv_region = -1, 
        price.price_nation, 
        price.price_tv_region 
       ), 
       price.price_site 
      ) AS price, 
      format.name AS format, 
      format.id AS format_id 
     FROM asset 
     JOIN site ON asset.site_id = site.id 
     JOIN day_part ON asset.day_part_id = day_part.id 
     JOIN media_owner ON site.media_owner_id = media_owner.id 
     JOIN area ON site.area_id = area.id 
     JOIN environment ON site.environment_id = environment.id 
     JOIN price ON site.price_id = price.id 
     JOIN postcode ON site.postcode_id = postcode.id 
     JOIN county ON postcode.county_id = county.id 
     JOIN tv_region ON postcode.tv_region_id = tv_region.id 
     JOIN metropolitan ON postcode.metropolitan_id = metropolitan.id 
     LEFT JOIN temp_media_index_1395751552 as audience_category 
      ON audience_category.site_id = site.id 
     JOIN frame_grouped ON frame_grouped.site_id = site.id 
     JOIN format ON frame_grouped.format_id = format.id 
     WHERE frame_grouped.format_id = 3 

     ORDER BY index DESC 
     LIMIT 100 OFFSET 0 

이 쿼리는이 오류 (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index DESC\n LIMIT 100 OFFSET 0' at line 35")

을주고있다하지만 쿼리에서 ORDER BY 절을 제거 할 때, 그것은 오류를 포기하지 않을거야.

아무도 내 쿼리에 mysql의 index 키워드를 사용하는 방법을 제안 할 수 있습니까?

+0

당신이해야 제거 '오프셋 0'그냥 당신이 tablename.index''처럼'index'셨어요 곳 – jmail

+0

내가 생각 .. 시도하거나 Alies 보낸 언급 'somedetails AS index'와 같은 이름 – jmail

답변

12

인덱스는 reserved word입니다. 견적이 (백 틱 포함) :

ORDER BY `index` DESC 
+0

나는 이것을 시도했지만 작동하지 않습니다. –

+0

당신이 그것을 인용 할 때 어떤 오류가 있습니까? 그것은 나에게 좋아 보인다. 쿼리 전후에 따옴표 나 다른 문자가 없는지 확인하십시오. – alexn

+1

@question - 따옴표 또는 백 틱으로 둘러 쌉니까? 다시 틱이어야합니다. – Kickstart