I wanted to create a view that selected animal_id, date from service_records table with conditions of Canine type and bath service, but I got an error message:
#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 ' service_type='B'.
How should I fix it?
Here is my code:
CREATE VIEW dogs_bath_records
AS
SELECT animal_id, date
FROM service_records
WHERE animal_type = 'Canine', service_type = 'B';
Use AND for multiple conditions
CREATE VIEW dogs_bath_records AS
SELECT animal_id, date
FROM service_records
WHERE animal_type='Canine'
AND service_type='B';
Related
The query is
SELECT account_id, type_id, client_id, avail_balance
FROM accounts
WHERE open_emp_id
IN (SELECT emp_id
FROM employee
WHERE (branch_id = 1111) AND (job_id NOT LIKE ‘HD%’);
Without the second WHERE condition, the query works fine. With that condition, I get
ERROR 1064 (42000): 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 '%’))' at line 1
I have the following query :
update event
set event.Paid = payment.amount
from event, payment
where payment.event_id = event.eid
The above query gives following error :
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 'from event, payment where payment.event_id = event.eid' at line
3
You join clause is wrong anyway
You should not use the implicit join syntax based on comma separated table name and where
you should use explicit join syntax (for mysql)
update event
INNER JOIN payment ON payment.event_id = event.eid
set event.Paid = payment.amount
I try this query
INSERT INTO shop.product(prod_id,model,desc) SELECT product.id_prod,prod_lang.name,product.ref from product left join product_lang on product_lang.id_prod = product.id_prod
However I got this error
SQL execution error # 1065.Response from the database:
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') SELECT product.id_prod,product_lang.name,product.ref from' at line 1
Two problems:
DESC is a reserved keyword. Use backquote (``) for desc.
Change prod_lang to product_lang in the query.
Solution:
INSERT INTO shop.product (prod_id,model,`desc`)
SELECT product.id_prod,product_lang.name,product.ref
from product left join
product_lang on product_lang.id_prod = product.id_prod
Note:
It is a good practice to use backquotes for all columns eventhough it is not a reserved keyword.
am new to Mysql
I want to retrieve all the columns containing StrainName=M18 from the database , but am getting error. please help me in this
SELECT *
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and strainName='M18';
ERROR 1064 (42000): 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 'strain.strainName,feature.contigId,feature.startPosition,feature.stopPosition,fe' at line 1
you need add comma after *
SELECT *, -- <<====== HERE
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and
strainName='M18';
to get all columns:
SELECT * from feature,strain
where feature.id=strain.id and strainName='M18';
to get specific columns :
SELECT
strain.strainName,
feature.contigId,
feature.startPosition,
feature.stopPosition,
feature.orfId,
feature.orfType,
feature.funcClassification,
feature.rastId,
feature.strand
from feature,strain
where feature.id=strain.id and
strainName='M18';
Im looking to add all products that dont have attribute_id = 12 into oc_product_attribute,
But getting a syntax error...
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 '12) select ocp.product_id from oc_product ocp where ocp.product_id not in (SE' at line 1
insert into `oc_product_attribute` (ocp.product_id, 12)
select ocp.product_id from oc_product ocp where ocp.product_id not in (SELECT oca.`product_id`
FROM `oc_product_attribute` oca where oca.attribute_id = 12)
Am I missing something here, quite new to SQL.
Usually you have to enumerate columns in insert statements.
insert into `oc_product_attribute` (ocp.product_id, 12)
must be
insert into `oc_product_attribute` (ocp.product_id, some_column_name)
and I guess it may be attribute_id.
For more details, please see the reference manual -> http://dev.mysql.com/doc/refman/5.6/en/insert-select.html