关于SQL的相关笔记【长期更新,只发一帖】
2018-06-17 23:10:40来源:未知 阅读 ()
场景【1】多表联查时,主表与关联表同时与同一张(第三张表)有关联,类似三角恋关系- -
涉及表:
- HOUSE:记录了房屋信息
- ROOMS:记录了房间信息
- HOUSE_STATUS:记录了状态信息的中文字段
房屋信息HOUSE表中有一个关于记录房屋状态的字段,status_id,与HOUSE_STATUS的主键表关联,而房间信息ROOMS表中,也有一个关于记录房屋状态的字段,也是status_id,当HOUSE与ROOMS建立关联查询时,两张表又分别需要与HOUSE_STATUS这张表建立关联查询。则出现了标题说的三角恋关系,查询方式只需要利用别名查询即可:
SELECT HOUSE.ID, HOUSE.NAME, HOUSE.FLOOR, HOUSE.EXPECT_PRICE, HOUSE.AREA_NUMBER, HOUSE.HAVE_KITCKEN, HOUSE.HAVE_BALCONY, PROVINCE.provinceName, CITY.cityName, AREA.areaName, COMMUNITY.ID community_ID, COMMUNITY.NAME community_Name, HOUSE_LAYOUT.NAME layout_Name, DECORATION_TYPE.NAME decorationType_Name, HOUSE_STATUS.STATUS_NAME houseStatus_Name, PAYMENT.PAYMENT_NAME payment_Name, RENT_MODE.ID rentMode_ID, RENT_MODE.NAME rentMode_Name, ROOMS.ID, ROOMS.ROOM_NO, ROOMS.HOUSE_STATUS_ID, ROOMS.AREA_NUMBER, ROOMS.EXPECT_PRICE, ROOMS.HAVE_WASHROOM, ROOMS.HAVE_KITCKEN, ROOMS.HOUSE_STATUS_ID, ROOMS.HAVE_DESK, ROOMS.HAVE_AIRCONDITIONING, ROOMS.HAVE_WARDROBE, ROOMS.HAVE_WATERHEATER, ROOMS.HAVE_WLAN, rooms_Status.ID rooms_StatusID, rooms_Status.STATUS_NAME rooms_StatusName FROM HOUSE JOIN PROVINCE ON HOUSE.PROVINCE_ID = PROVINCE.provinceID JOIN CITY ON HOUSE.CITY_ID = CITY.cityID JOIN AREA ON HOUSE.AREA_ID = AREA.areaID JOIN COMMUNITY ON HOUSE.COMMUNITY_ID = COMMUNITY.ID JOIN HOUSE_LAYOUT ON HOUSE.LAYOUT_ID = HOUSE_LAYOUT.ID JOIN DECORATION_TYPE ON HOUSE.DECORATION_TYPE_ID = DECORATION_TYPE.ID JOIN HOUSE_STATUS ON HOUSE.HOUSE_STATUS_ID = HOUSE_STATUS.ID JOIN PAYMENT ON HOUSE.EXPECT_PAYMENT_ID = PAYMENT.ID JOIN HOUSE_RENT_MODE ON HOUSE.ID = HOUSE_RENT_MODE.HOUSE_ID JOIN RENT_MODE ON HOUSE_RENT_MODE.RENT_MODE_ID = RENT_MODE.ID JOIN ROOMS ON HOUSE.ID = ROOMS.HOUSE_ID JOIN HOUSE_STATUS rooms_Status ON ROOMS.HOUSE_STATUS_ID = rooms_Status.ID WHERE HOUSE.ID = 1
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- MySQL replace函数怎么替换字符串语句 2020-03-09
- PHP访问MySQL查询超时怎么办 2020-03-09
- mysql登录时闪退 2020-02-27
- MySQL出现1067错误号 2020-02-27
- mysql7.x如何单独安装mysql 2020-02-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash