complex SQL statement

Discussion in 'Databases' started by hasanbasri, Dec 9, 2009.

  1. #1
    hello all
    for me as a beginner it's a complex statement
    I want sql statement that do the following
    retrive all records that meet the following condition
    name field must contain one or more of the following patterns [%adm%,%use%,%joh%,.....etc].
    for example I want employers informations about all employers that names are contain the substrings: [adm OR use OR joh ....]

    by the way the substrings are contained in array or comma limited string.
    thanks in advance
     
    hasanbasri, Dec 9, 2009 IP
  2. SouthamptonAngel

    SouthamptonAngel Peon

    Messages:
    88
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    select * from table
    where name like '%adm%' or '%use%' or '%joh%';
     
    SouthamptonAngel, Dec 9, 2009 IP
  3. nashhull

    nashhull Peon

    Messages:
    141
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Right. Name with '%adm%'.
     
    nashhull, Dec 9, 2009 IP
  4. hasanbasri

    hasanbasri Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you
    your statement will work if I know how many patterns I want to find but the patterns are in array like that
    array('adm','use','sar','ali','joh',,,,,,,,,,,,,etc)

    but not that what I mean:
    I mean something like this :

    
    
    select * from table1 
    where name IN ('%adm%','%use%','%joh%','%sar%',,,,,,,,,,,etc.)
    
    Code (markup):
    I want employers informations about all employers that names are contain the substrings: [adm OR use OR joh ....etc] , note that the substrings are contained in array
     
    hasanbasri, Dec 9, 2009 IP