-1

Let's say we have this query:

query = "SELECT surname FROM set_payment WHERE surname = %s"
mycursor.execute(query,("Smith",))

If we have the surname 'Smith' for example in our table it should print Smith. Is there a way to search for something by searching a part of it? For example, if a search for Sm to print all surnames that contain the letters 'Sm'?

  • 1
    Sounds like you need the [`LIKE`](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like) operator. – khelwood Jan 02 '22 at 10:45

2 Answers2

0

Yes of course it is possible.

You can use "where" with "like" in MySQL query.

For your search you can write the query like this:

WHERE surname LIKE '%sm%';

this searches all names that contains 'sm'.

0

you can use the LIKE operator using %. example: WHERE surname LIKE '%sm%'

Snap
  • 36
  • 3