2

I try to set the result of a select in a variable(To show it in my result) but I obtain an error

This is my code :

SELECT 8_Type,SET @var= (select Name from variables where  Ch8_ID  = variables.ID)
FROM TTable ;

and when I change my code like bellow, this is what I want but I need to change the name of the column :

SELECT 8_Type, (select Name from variables where  Ch8_ID  = variables.ID)
FROM TTable ;![enter image description here][1]

I obtain in the column the query like this image.

The second query

3
  • Why are you using a subselect in SELECT clause? I am not following what you are trying to do. Commented Jan 16, 2013 at 22:40
  • 1
    The error is private or do you want to share the error? Commented Jan 16, 2013 at 22:41
  • The error is : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version.... Commented Jan 16, 2013 at 22:44

2 Answers 2

1

Provide a column alias for the expression... SELECT expr AS my_name e.g.

SELECT 8_Type
     , (select Name from variables where Ch8_ID = variables.ID) AS my_name
 FROM TTable

MySQL will return "my_name" as the label for the column (in the metadata) for the resultset.

(But it's not at all clear what your SQL statement is trying to do though.)

Sign up to request clarification or add additional context in comments.

Comments

0

SELECT field AS put_name_result FROM ttable

Comments

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.