How to select from table where name

→ Are you a new visitor? Please visit the page guidance for new visitors ←

How to select from table where name

Not the most ingenious article name, but will go with this one for now. I’m going to write a few tricks that I stumble upon working with mysql queries and the select method. This is about how to select from table where name is equal to something related in that field name or table.

A simple example would be bellow:

The where clause

Using the where clause you can extract specific records that meet some specific criterias.

The above is a simple example where we get from table name table the field1 and field2 contents. Now this will work in almost all cases, we should not have any errors with simple data. But what if we want use the where statement? This radically complicates things, well for most advance uses these will be easy, but for those starting programing recently they will need to get used to the logic here.

A simple example using where statement.

Again, this is a a simple example, this can get a lot more complicated with using multiple mysql operators. For example, a more complicated sql statement would be:

Now I got something really tricky, for users that will want to use special characters in their queries, for example building or people names that have a quote in their names, they will encounter some errors.

To get around this, you will need to escape the sql statement, this can be done using something similar to be the bellow example:

With this, the quote from the person name will be escaped properly and query should work as expected.

Request an article ←