Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there any way to do something like :

SELECT * FROM TABLE WHERE COLUMN_NUMBER = 1;

?

share|improve this question
What is the use case for this? Even if it's possible, any changes to the schema break your query. – Tom Studee 17 hours ago
take a look at this stackoverflow.com/questions/7494372/… – zan 17 hours ago

2 Answers

No, you can't. Column order doesn't really matter in MySQL. See the below question for more details.

mysql - selecting values from a table given column number

share|improve this answer

If you have a column named COLUMN_NUMBER and you want to retrieve rows where that column has a value of '1', that query should do the trick.

I suspect that what you are trying to do is reference an expression in the select list with an alias. And that is not supported. An expression in the WHERE clause that references a column must reference the column by name.

We can play some tricks with inline views, to give an alias to an expression, but this is not efficient in terms of WHERE predicates, because of the way MySQL materializes a derived table. And, in that case, its a name given to the column in the inline view that has to be referenced in the outer query.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.