안드로이드 개발 질문/답변
(글 수 45,052)
제가 테이블이 여러개가 있는데요..
만약 buildings, offices, retails 이렇게 있다고 치면..
특정 스트링을 검색해서 데이터를 얻어 오려 하는데요..
db.query("buildings"+","+offices"+","+"retails", new String[]{"name","detail","call_no"},"name like"+" '%'"+target+" '%' ",null,null,null,null);
이게 맞는지요...여러 테이블을 동시에 select 하고 싶으면 "buildings"+","+offices"+","+"retails" 이렇게 하는게 맞나요?
궁금합니다...감사 합니다.
만약 buildings, offices, retails 이렇게 있다고 치면..
특정 스트링을 검색해서 데이터를 얻어 오려 하는데요..
db.query("buildings"+","+offices"+","+"retails", new String[]{"name","detail","call_no"},"name like"+" '%'"+target+" '%' ",null,null,null,null);
이게 맞는지요...여러 테이블을 동시에 select 하고 싶으면 "buildings"+","+offices"+","+"retails" 이렇게 하는게 맞나요?
궁금합니다...감사 합니다.
2009.12.03 11:46:57
이게 가능한지는 잘 모르겠네요.
알고 싶은 name이 buildings 테이블에 있고, detail은 offices 테이블에 있고, call_no는 retails 테이블에 있다고 할때,
db.rawQuery("SELECT bil.name, off.detail, ret.call_no From buildings bil, offices off, retails ret WHERE bil.name = "
+ target + " AND bil.name = off.name AND bil.name = ret.name");
이러면 될 것 같기도 한데. 확인은 해 봐야 할듯..
알고 싶은 name이 buildings 테이블에 있고, detail은 offices 테이블에 있고, call_no는 retails 테이블에 있다고 할때,
db.rawQuery("SELECT bil.name, off.detail, ret.call_no From buildings bil, offices off, retails ret WHERE bil.name = "
+ target + " AND bil.name = off.name AND bil.name = ret.name");
이러면 될 것 같기도 한데. 확인은 해 봐야 할듯..
SQL 문에서 여러 DB에서 데이터를 얻어오기 위해서 JOIN을 사용을 하는데..
저도 그걸 그냥 query 함수로 해보려고 했었는데 잘 안되더라구요 ..
그래서 rawQuery(sql,null); 함수를 사용했는데요.. 옆에 매개변수중에 sql에 sql 문장을 넣어주시구요, null 부분은 그 문장의 값을 넣는건데 저도 이 부분에 오류가 발생해서 그냥 sql 문에서 다 작성해주고 null로 주었습니다.
다른 방법 아시는분 더 알려주세요~ 저도 궁금하네요.. ㅎㅎ