2

I am not being able to perform select query on a subset of columns of a database in IBM DB2.

select * from user 

This works. But

select username from user

doesn't work. Here's the screenshot.enter image description here

Mureinik
  • 297,002
  • 52
  • 306
  • 350
nishantsingh
  • 4,537
  • 5
  • 25
  • 51

1 Answers1

1

username is a reserved word. The "proper" solution would probably be to have a column name that isn't a reserved word, such as user_name. If changing the column name isn't an option, you could use double-quotes (") to escape it:

SELECT "username" FROM user
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 1
    And if you quote it, case matters. "username" is not the same as "USERNAME" – Charles Aug 22 '15 at 18:41
  • 1
    "username" is not a reserved word. However, as @Charles indicates, the column was apparently created in lowercase, so now you have to quote it each time you reference it (as well as `"password"` and `"admin"` columns). – mustaccio Aug 22 '15 at 21:07