Matthew Smart Matthew Smart - 1 month ago 8
SQL Question

MYSQL statement, whats wrong?

I have a MySQL query that fails.

SELECT `name`,`desc`,`address_line1`,`address_line2`,`address_line3`,`city`,`county`,`postcode`,`phone`,`website` `type` as `category`
FROM `hw_services`
JOIN `types`ON `types`.`ID` = `hw_services`.`type`
WHERE `healthwatchID` = 54


I want to select the columns from hw_services but I want
type
to display as
category
.

Then the type field from
hw_services
relates to the ID in the
types
table.

Any ideas?

Answer

Correct the query. It is missing comma(,).

Corrected query:

SELECT 
`name`,`desc`,`address_line1`,`address_line2`,`address_line3`,`city`,`county`,`postcode`,`phone`,`website`, `type` as `category`
FROM  `hw_services` 
JOIN `types`ON `types`.`ID` = `hw_services`.`type`
WHERE  `healthwatchID` = 54
Comments