-4

I have a column name 'Segment Type', but when i use SELECT Segment Type FROM results; it gives me error (unknown column 'Segment' in field list).

But this code works if it written Segment_type with the underscore. So how to i select a column name that does not have a underscore?

I tried using multiple ways of selecting but because there is no underscore in the column name i cant select it.

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • Review https://dev.mysql.com/doc/refman/8.0/en/identifiers.html#:~:text=Certain%20objects%20within%20MySQL%2C%20including,syntax%20for%20identifiers%20in%20MySQL. – P.Salmon Jun 22 '23 at 13:31
  • 2
    Your title says "MySQL" so why have you tagged [[tag:sql-server]] and [[tag:sqlite]] as well? What do *all three* products have to do with what you are asking? How does Python become involved? – Thom A Jun 22 '23 at 13:31
  • Use underscore in the column name, to avoid future problems. – jarlh Jun 22 '23 at 13:31
  • Avoid using spaces in column names. – Wallace Jun 22 '23 at 13:32
  • you need to use Backtick - SELECT ` Segment Type ` FROM results (remove spaces from before and after, I just added to make it visible and not allow SO to treat it as code – Tushar Gupta Jun 22 '23 at 13:39

1 Answers1

-3

Use double quotes around the column names.

select "Segment Type" from 

MySQL will parse the contents of the double quotes as a string literal.

Alan
  • 1,746
  • 7
  • 21
  • 1
    This only replaces all the info in the row as Segment Type, it doesnt grab the info in Segment type. – Mornay Marais Jun 22 '23 at 13:34
  • Ah my bad, I just checked and I'm wrong. It's a SQL dialect thing. In Postgres what I said is correct. In MYSQL one uses backticks `\`` – Alan Jun 23 '23 at 10:55