I have a table called email from which I fetch email. The table has email in this order
我有一个名为email的表,我从中获取电子邮件。该表格按此顺序发送电子邮件
-
asda@gmaila.omc
123@dsad.com
name@gmail.com
asda@gmaila.omc 123@dsad.com name@gmail.com
Now If I make this query
现在如果我进行此查询
SELECT * FROM email WHERE (email IN ( 'asda@gmaila.omc' ,'123@dsad.com' , 'name@gmail.com' )) AND email!='' LIMIT 3
I get this
我明白了
123@dsad.com
asda@gmaila.omc
name@gmail.com
but I want to get result on the basis of the arguments in the IN clause
If you notice in the IN
I mentioned asda@gmaila.omc
first, I dont think order by clause will help me here Any other way of solving this issue?
但是我想根据IN子句中的参数得到结果如果你在IN中我注意到首先提到asda@gmaila.omc,我不认为order by子句会帮助我这里解决这个问题的其他方法吗?
1 个解决方案
#1
3
One possible approach is using FIELD() MySQL function:
一种可能的方法是使用FIELD()MySQL函数:
SELECT *
FROM email
WHERE FIELD(email, 'asda@gmaila.omc', '123@dsad.com', 'name@gmail.com') <> 0
ORDER BY FIELD(email, 'asda@gmaila.omc', '123@dsad.com', 'name@gmail.com');
As FIELD
returns 0 if its first argument isn't equal to any other, FIELD(str, 'aaa', 'bbb'...) <> 0
clause is roughly equivalent to str IN ('aaa', 'bbb')
.
如果FIELD的第一个参数不等于任何其他,则返回0,FIELD(str,'aaa','bbb'...)<> 0子句大致相当于str IN('aaa','bbb') 。
#1
3
One possible approach is using FIELD() MySQL function:
一种可能的方法是使用FIELD()MySQL函数:
SELECT *
FROM email
WHERE FIELD(email, 'asda@gmaila.omc', '123@dsad.com', 'name@gmail.com') <> 0
ORDER BY FIELD(email, 'asda@gmaila.omc', '123@dsad.com', 'name@gmail.com');
As FIELD
returns 0 if its first argument isn't equal to any other, FIELD(str, 'aaa', 'bbb'...) <> 0
clause is roughly equivalent to str IN ('aaa', 'bbb')
.
如果FIELD的第一个参数不等于任何其他,则返回0,FIELD(str,'aaa','bbb'...)<> 0子句大致相当于str IN('aaa','bbb') 。