How can I fix the Syntax Error in the subquery? [closed] - mysql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to find the Age based off date of birth. I keep getting a syntax error in the subquery.
I'm getting on error on the - CUST_DOB /365,0) As Age from customer; to use the correct syntax. Error Code 1064
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() – CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;

There is a problem with the minus (-) sign. please use it like
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() - CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;

Related

CASE clause inside WHERE clause [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
can anyone tell me why I can not run this code in SQL Management studio?
Thanks in advance.
SELECT * FROM TabKontaktJednani
where
TabKontaktJednani.Typ IN (
CASE 'ERP'--(SELECT ALIAS FROM TabCisZam where LoginId = SUSER_NAME())
WHEN 'ERP'
THEN ('HeO','OST')
WHEN 'TO'
THEN ('SW','OST')
END)
The reason you can't run that code is that CASE expressions can only return one scalar value, not a list of values.
Your CASE expression returns a tuple. That is not allowed in SQL. But as MySQL supports a boolean data type, a CASE expression may result in a boolean:
SELECT *
FROM tabkontaktjednani
WHERE
CASE (SELECT alias FROM tabciszam WHERE loginid = suser_name())
WHEN 'ERP' THEN typ IN ('HeO', 'OST')
WHEN 'TO' THEN typ IN ('SW', 'OST')
END;

Error While Deleting row from multiple dependent tables [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
ERROR: syntax error at or near "r"
Query was:
Delete r,ur from un_received_compansation_reason ur join received_compensation_info r on received_compensation_info.compensation_info_id = un_received_compansation_reason.compensation_info_id where compensation_info_id=2
You have specific table aliases, so try writing the query as:
Delete r, ur
from un_received_compansation_reason ur join
received_compensation_info r
on r.compensation_info_id = ur.compensation_info_id
where r.compensation_info_id = 2;
You need to use table aliases in time joining key like below
Delete r,ur from un_received_compansation_reason ur join
received_compensation_info r on
r.compensation_info_id = ur.compensation_info_id
where ur.compensation_info_id=2

query to retrieve correct properties in the range [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to retrieve all the properties in the range 2200000(min_price) to 2700000(max_price)
The query should look like
SELECT *
FROM properties
WHERE ( ((raw_min >= '{$min_price}')
OR (raw_min <= '{$max_price}'))
AND ((raw_max >= '{$min_price}')
OR (raw_max <= '{$max_price}')))
AND (..)
query should satisfy the below 6 conditions
raw_min - raw_max
(1) 1000000-2000000 (false)
(2) 1500000- 2400000 (true)
(3) 2300000-2600000 (true)
(4) 2500000-3000000 (true)
(5) 3200000-5000000 (false)
(6) 2000000-3000000 (true)
Please try this query:-
SELECT *
FROM properties
WHERE (raw_min between 2200000 AND 2700000)
OR (raw_max between between 2200000 AND 2700000)
OR (raw_min <= 2200000 && raw_max >= 2700000)
Please check I have updated the query.

Date is showed with unexpected value in html [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I used Bootstrap datepicker to get date from the user. I stored that value in database.
But when i render this date in html, it showed unexpected value with the date !
I give the screen shot of the result.
Can anyone help me to solve this ?
How have you stored the date in the database?
Make sure you used DATETIME and not VARCHAR
Also how did you get the date from the database?
I would use:
$query = "SELECT DATE_FORMAT(ColumnName, '%Y-%m-%d %H:%i:%s') AS Date FROM Table";
$result = mysqli_query($cxn,$query) or die(mysqli_error());
$date = $result->fetch_object()->Date;

MySql syntax error is thrown in spite of writting the correct query [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have been trying this query in different formats yet I don't know why I get this weird error.
insert into details ('refno','membershipno','name','dob','year_of_passing_diploma','phone','address','email','mobileno','city','state','pincode','degree','college') values('1001','2001','ragesh','1991-06-27','2012','24423021','D1, silver star apartments sec','rageshcv#gmail.com','9840526989','chennai','tamil nadu','600020','pilot','newzeleand','98455 27/06/14','IOB chennai','Chetta kadai','nandanam','leatrher','MD','3','24405158','chennai')
I don't find anything wrong in this query still I am getting the error
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 ''refno','membershipno','name','dob','year_of_passing_diploma','phone','address',' at line 1
Has anyone experienced the same issue?
You cannot use single quotes around your column identifiers. Either use ticks or nothing:
insert into details (refno,membershipno,name,dob,year_of_passing_diploma,phone,address,email,mobileno,city,state,pincode,degree,college) values('1001','2001','ragesh','1991-06-27','2012','24423021','D1, silver star apartments sec','rageshcv#gmail.com','9840526989','chennai','tamil nadu','600020','pilot','newzeleand','98455 27/06/14','IOB chennai','Chetta kadai','nandanam','leatrher','MD','3','24405158','chennai')
or
insert into details (`refno`,`membershipno`,`name`,`dob`,`year_of_passing_diploma`,`phone`,`address`,`email`,`mobileno`,`city`,`state`,`pincode`,`degree`,`college`) values('1001','2001','ragesh','1991-06-27','2012','24423021','D1, silver star apartments sec','rageshcv#gmail.com','9840526989','chennai','tamil nadu','600020','pilot','newzeleand','98455 27/06/14','IOB chennai','Chetta kadai','nandanam','leatrher','MD','3','24405158','chennai')
Apart from quoting: you have 14 columns and 23 values in your query
Single quotes (') are used to denote string literals. When refering to columns, you should use forward-quotes, or no quotes at all:
insert into details
(refno,membershipno,name,dob,year_of_passing_diploma,phone,address,email,mobileno,city,state,pincode,degree,college)
values('1001','2001','ragesh','1991-06-27','2012','24423021','D1, silver star apartments sec','rageshcv#gmail.com','9840526989','chennai','tamil nadu','600020','pilot','newzeleand','98455 27/06/14','IOB chennai','Chetta kadai','nandanam','leatrher','MD','3','24405158','chennai')