Basudev
Basudev

Reputation: 155

want to take a database value in a variable

i need to take a value from database in a variable in shell programming. i am using below command. but getting error.

applicant= `mysql -uroot -p123456 -e 'SELECT applicant FROM 
    leave where status="Applied" and applying_date= curdate() 
    order by applying_date' comviva|tail -1`;
ERROR 1064 (42000) at line 1: 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 'leave where status="Applied" and 
applying_date= curdate() order by applying_date' at line 1

Upvotes: 0

Views: 49

Answers (1)

Barmar
Barmar

Reputation: 781088

LEAVE is a reserved word, you need to put it in backticks. Also, there must not be a space after = in the variable assignment.

applicant=$(mysql -uroot -p123456 -e 'SELECT applicant FROM 
    `leave` where status="Applied" and applying_date= curdate() 
    order by applying_date' comviva|tail -1);

Upvotes: 1

Related Questions