只要name(姓名)+任意一个电话相同的情况下,就提示该学员已存在

fkueyga6 2015-06-26 10:25:42
xy表:
id name(姓名) mother_mobile(妈妈电话) father_mobile(爸爸电话) home_tel(家庭电话)

我现在是想做个判断,只要name(姓名)+任意一个电话相同的情况下,就提示该学员已存在
下面是我写的SQL语句,好复杂,而且我不知道对不对,有没有更简单的?
xy.name='".$arr_xy_info['name']."'
and (
((xy.mother_mobile='".$arr_xy_info['mother_mobile']."' or xy.father_mobile='".$arr_xy_info['mother_mobile']."' or xy.home_tel='".$arr_xy_info['mother_mobile']."') and xy.father_mobile<>'' and xy.home_tel<>'' and xy.mother_mobile<>0)
or ((xy.mother_mobile='".$arr_xy_info['father_mobile']."' or xy.father_mobile='".$arr_xy_info['father_mobile']."' or xy.home_tel='".$arr_xy_info['father_mobile']."') and xy.father_mobile<>'' and xy.home_tel<>'' and xy.mother_mobile<>0)
or ((xy.mother_mobile='".$arr_xy_info['home_tel']."' or xy.father_mobile='".$arr_xy_info['home_tel']."' or xy.home_tel='".$arr_xy_info['home_tel']."') and xy.father_mobile<>'' and xy.home_tel<>'' and xy.mother_mobile<>0)
)
...全文
300 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2015-07-11
  • 打赏
  • 举报
回复
$sqlstr = "select id from xy where name='".$arr_xy_info['name']." and id in(select id from xy where mother_mobile='".$arr_xy_info['mother_mobile']."' or father_mobile='".$arr_xy_info['father_mobile']."' or home_tel='".$arr_xy_info['home_tel']."')";
tianboo 2015-07-07
  • 打赏
  • 举报
回复
引用 3 楼 tianboo 的回复:
不考虑效率的前提下: select id from ( select id,name,concat(mother_mobile,father_mobile,home_tel) `phones` from xy ) `a` where name='test' and phones likes('%181822002200%') limit 0,1;
更正一下.like 写成 likes
tianboo 2015-07-07
  • 打赏
  • 举报
回复
不考虑效率的前提下: select id from ( select id,name,concat(mother_mobile,father_mobile,home_tel) `phones` from xy ) `a` where name='test' and phones likes('%181822002200%') limit 0,1;
hchyyooh 2015-06-26
  • 打赏
  • 举报
回复
同楼上,用程序判断吧
  • 打赏
  • 举报
回复
个人觉得用程序的写的话简单些

21,892

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧