Strict matching of strings and integers

前端 未结 2 1494
醉梦人生
醉梦人生 2020-12-12 02:56

I am writing a flexible search mechanism for a customer\'s website. I am utilizing union clauses to query a number of different fields in the database in search of a string

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 03:26

    How about replacing:

    SELECT * FROM test_table WHERE phone = 'email@example.com'
    

    with:

    SELECT * FROM test_table WHERE phone = 'email@example.com' and phone <> 0
    

    <> means different from.

    This will work for you because you are using 0 in the phone column to mean there isn't a phone number (although it would be better style to use NULL for no phone number).

提交回复
热议问题