0

I'm executing the following query, to update the data in my database:

mysql -u root -ppassword -e "UPDATE table SET data = 1 WHERE id = 5"

Is there a way to execute the same query, but with the SELECT statement ? Of course there is, but how can I fetch the returned value then? Is that even possible?

2
  • You will have to do a better job of explaining what you are after. What do you want to select? Do you want to update the table with values from another select? Commented Mar 12, 2012 at 22:27
  • @nnichols No, don't look at the update one. All I need is something like: mysql -u root -ppassword -e "SELECT something from mytable where id = 1 LIMIT 1" (there will always be a limit 1), but how can I fetch returned value (something)? Commented Mar 12, 2012 at 22:37

1 Answer 1

1
mysql -u root -ppassword -e "UPDATE table SET data = 1 WHERE id = 5; SELECT data FROM table WHERE id = 5"
Sign up to request clarification or add additional context in comments.

6 Comments

Fine, but HOW can I fetch the "data" returned by SELECT?
@Cyclone, what do you mean by "I can fetch"? What are you going to do having fetched?
Normally, mysql command line will return something like this: pastebin.com/raw.php?i=x7zu5jcH , I want it to return signle Hello (return value). +1 for nw :)
@Cyclone, I currently do not have a mysql at hand, but I do know that the format of the output can be controlled by various options. For example, -X will output the data as XML, and there are options to skip table headers.
I've looked at man mysql, and found the -s parameter, which cut all of the +-+-+-+- string, but there are now 2 lines: Field Name and below the field value is shown, it all I need is to cut the first line of returned string in bash :P I guess there is a function for this !
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.