sql searching multiple words in a string

前端 未结 8 733
故里飘歌
故里飘歌 2020-12-09 02:35

What is the most efficient and elegant SQL query looking for a string containing the words \"David\", \"Moses\" and \"Robi\". Assume the table is named T an

相关标签:
8条回答
  • 2020-12-09 03:15

    Oracle SQL:

    There is the "IN" Operator in Oracle SQL which can be used for that:

    select 
        namet.customerfirstname, addrt.city, addrt.postalcode
    from schemax.nametable namet
    join schemax.addresstable addrt on addrt.adtid = namet.natadtid
    where namet.customerfirstname in ('David', 'Moses', 'Robi'); 
    
    0 讨论(0)
  • 2020-12-09 03:21

    In SQL Server 2005+ with Full-Text indexing switched on, I'd do the following:

    SELECT *
      FROM T
     WHERE CONTAINS(C, '"David" OR "Robi" OR "Moses"');
    

    If you wanted your search to bring back results where the result is prefixed with David, Robi or Moses you could do:

    SELECT *
      FROM T
     WHERE CONTAINS(C, '"David*" OR "Robi*" OR "Moses*"');
    
    0 讨论(0)
提交回复
热议问题