帮助这个搜索查询

时间:2011-03-03 17:22:35

标签: mysql sql

它在phpmyadmin syntax error near 'SELECT c.candidate_id AS candidate_id,c.date_time_stamp AS candidate_date_time,c' at line 1

中说
SELECT * FROM states ORDER BY name ASC 

SELECT c.candidate_id AS candidate_id,
       c.date_time_stamp AS candidate_date_time,
       c.first_name AS first_name, c.last_name AS last_name,
       c.availability_date AS availability_date,
       c.experience_years AS experience_years,
       c.phone AS phone,c.phone_alternate AS phone_alternate,
       c.email AS email,c.bridge AS bridge,c.hot AS hot,
       c.submitted AS submitted,c.placed AS placed,
       sp.abbreviation AS specialty_abbreviation,
       jt.name AS candidate_job_type,s.first_name AS staff_first_name 
FROM candidates c 
     LEFT JOIN specialties sp ON sp.specialty_id=c.specialty_id 
     LEFT JOIN candidate_job_types jt ON jt.candidate_job_type_id=c.candidate_job_type_id 
     LEFT JOIN staff s ON s.staff_id=c.staff_id 
WHERE c.active=1 AND 
      ( CONCAT_WS(' ', c.first_name, c.last_name) LIKE '%gmail%' OR c.phone = 'gmail'       OR 
      c.phone_alternate = 'gmail' OR c.email = 'gmail') GROUP BY c.candidate_id 
 ORDER BY c.date_time_stamp DESC LIMIT 0,100 

3 个答案:

答案 0 :(得分:6)

由于合并了两个SELECT语句,您有错误。如果你用;分隔它们,它应该有效。

   SELECT * 
     FROM states
 ORDER BY name ASC;

   SELECT c.candidate_id AS candidate_id,c.date_time_stamp AS candidate_date_time, 
          c.first_name AS first_name, c.last_name AS last_name,
          c.availability_date AS availability_date,
          c.experience_years AS experience_years,c.phone AS phone,
          c.phone_alternate AS phone_alternate,c.email AS email,c.bridge AS bridge,
          c.hot AS hot,c.submitted AS submitted,c.placed AS placed,
          sp.abbreviation AS specialty_abbreviation,jt.name AS candidate_job_type,
          s.first_name AS staff_first_name
     FROM candidates c
LEFT JOIN specialties sp
       ON sp.specialty_id=c.specialty_id
LEFT JOIN candidate_job_types jt
       ON jt.candidate_job_type_id=c.candidate_job_type_id
LEFT JOIN staff s
       ON s.staff_id=c.staff_id
    WHERE c.active=1
      AND ( CONCAT_WS(' ', c.first_name, c.last_name) LIKE '%gmail%'
         OR c.phone = 'gmail'
         OR c.phone_alternate = 'gmail'
         OR c.email = 'gmail'
          )
 GROUP BY c.candidate_id
 ORDER BY c.date_time_stamp DESC
    LIMIT 0,100;

答案 1 :(得分:0)

您正在一起执行两个select语句。使用分号:

SELECT * FROM states ORDER BY name ASC;
SELECT c.candidate_id AS [...]

答案 2 :(得分:0)

问题刚刚开始:SELECT * FROM states ORDER BY name ASC SELECT c.candidate_id ...

使用分号分隔不同的搜索:SELECT * FROM states ORDER BY name ASC; SELECT c.candidate_id...