[求助]关于数据库查询的问题
rand_id department_id department_name
30 3001 武汉市
40 3001010 蔡甸区
40 3001011 江夏区
40 3001012 黄陂区
40 3001013 新洲区
30 3002 黄石市
40 3002011 大冶市
40 3002012 阳新县
如果我通过一个textbox获得了武汉市这个字段,那么应该怎么写语句同时把蔡甸区和江夏区同时从数据库中查找出来?
sqlWhere = " where t.department_id = ' " & UploadDepart & " ' "
sql = "select t.department_name,t.department_id from t_department t " & sqlWhere & " order by t.department_id "
我这么写只能查出具体部门的记录!请高人指教一下!
------解决方案--------------------抱歉,多打了几个字
应该是这样子:
sqlWhere = " where SUBSTRING(t.department_id,1,4) = ' " & UploadDepart & " ' AND t.department_id <> ' " " & UploadDepart & " ' "
sql = "select t.department_name,t.department_id from t_department t " & sqlWhere & " order by t.department_id "
如果你只想取前两条,那么直接top 2 就可以了