Query Database

Ok. I am problem with querying my database. When I use the query command "SELECT * FROM TableName", then I have no problem. It shows the results as expected. But when I try to choose a certain field as follows:

"SELECT * FROM TableName WHERE Song Name = 'Ben Stuart - A moment';

It doesnt work. Can someone tell me what the problem is


Answer this question

Query Database

  • Bramx

    Everyone's answer was correct. So I am not going to mark one as the answer. I would just like to let everyone know that all these answers were correct. Thank you for a quick response.

  • Mark.Sch

    ShellShock is on the money.  that's the most correct answer.  Field names should be in brackets when the name of the field is an sql keyword or there are non alphanumeric characters.


  • Giorgi Moniava

    If you are using SQL Server, you can also square brackets:

    "SELECT * FROM TableName WHERE [Song Name] = 'Ben Stuart - A moment';

    But the best solution is definitely to remove the space from the column name.

  • Anonymous34134

    One of the fastest solution is to add double quotes around the field name "Song Name" in Where clause. But the common way in database design is to use "SongName"(no space) as Database field's name.


  • RWP

    "SELECT * FROM TableName WHERE Song Name = 'Ben Stuart - A moment';

    Over here, the String is not closed with inverted quotes :)
    If the problem persists you might want to change Song Name to SongName instead. That would work.

    Abhi


  • Carl Karsten

    Well, when you are using query, the space between field "Song Name" cause the problem.
  • Query Database