2013-10-30 23 views
0

表名:customer_datails匹配2個valuse定期EXP沒有和條件

customer_id   customer_name 
101     Hari prasad 
102     Hari 
103     prasad 
104     Vara Prasad 
105      Sri Hari bandaru 
106     Raja Shekhara Prasad 

我有上述表。我想顯示CUSTOMER_ID的名字是'Hari'和'prasad'。但我需要與'REGEXP'沒有和條件。我嘗試了下面那些正在工作的查詢。

實施例1)

select cistomer_id from customer_details where customer_name LIKE 'Raja' 'Prasad'; 

o/p: 106 

實施例2)

select cistomer_id from customer_details where customer_name LIKE 'Raja' AND 
      customer_name LIKE 'Prasad'; 

    O/P: 106. 

我需要與上面的regexp查詢,而無需 「和」 條件(意味着我不想使用CUSTOMER_NAME字段不止一次在條件如Ex2)

+0

你的第一個查詢甚至不會工作,因爲語法是無效的,並與ID 106,第二個將不返回記錄或者是因爲你不使用佔位符在LIKE比較,這使得它的工作一樣簡單'='。而你實際上在問什麼,我甚至都不明白。 – CBroe

回答

-1

假設您關心訂單,以下查詢將起作用:

SELECT customer_id 
    FROM customer_details 
WHERE customer_name LIKE '%Raja%Prasad%'; 

如果你需要他們以任何順序,你必須使用RLIKE

SELECT customer_id 
    FROM customer_details 
WHERE customer_name RLIKE 'Raja.*Prasad|Prasad.*Raja'; 
-1

這應做到:

select customer_id from customer_details where customer_name REGEXP '(.*Raja.*)|(.*Prasad.*)'; 

這可能會幫助你

0

使用下面的腳本:從customer_details 選擇CUSTOMER_ID其中如first_name在( '拉加', '普拉薩德');

+0

OP表中有'first_name'字段嗎? – mdml