search
HomeBackend DevelopmentPHP Tutorialthinkphp关联查询问题,join

thinkphp 关联查询

$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where(array('hospital_id'=>array('exp','is not null')))->select();
大神们看看,where(array('hospital_id'=>array('exp','is not null')))这句话是什么意思?结果显示出来所有的医院,但我只想查某一个,把医院id等于$data,怎么做

回复讨论(解决方案)

没人会吗?难到就那么难吗

从字面理解是hostpital_id中非NULL空的都选择

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select(); 

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('r_hospital on r_department.hospital_id=r_hospital.id')->where($condition)->select(); 
恩,确实是这种方法。三级关联的怎么写,再添加一个医生doctor的id

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id  left join doctor on doctor.id = xx.id')->where($condition)->select(); 

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id  left join doctor on doctor.id = xx.id')->where($condition)->select(); 
谢了

$condition['hospital_id'] = $data;
// 把查询条件传入查询方法
$result = $room->join('left join r_hospital on r_department.hospital_id=r_hospital.id  left join doctor on doctor.id = xx.id')->where($condition)->select(); 
这个是三级关联的吗?貌似不行呀。帮我写个三级关联的吧,医生属于科室,科室属于医院这种关系。我弄了很久了,就是不会

请帖出3张表结构

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySql中如何使用JOINMySql中如何使用JOINJun 04, 2023 am 08:02 AM

JOIN的含义就如英文单词“join”一样,连接两张表,大致分为内连接,外连接,右连接,左连接,自然连接。先创建两个表,下面用于示例CREATETABLEt_blog(idINTPRIMARYKEYAUTO_INCREMENT,titleVARCHAR(50),typeIdINT);SELECT*FROMt_blog;+----+-------+--------+|id|title|typeId|+----+-------+--------+|1|aaa|1||2|bbb|2||3|ccc|3|

MySQL Join使用原理是什么MySQL Join使用原理是什么May 26, 2023 am 10:07 AM

Join的类型leftjoin,以左表为驱动表,以左表作为结果集基础,连接右表的数据补齐到结果集中rightjoin,以右表为驱动表,以右表作为结果集基础,连接左表的数据补齐到结果集中innerjoin,结果集取两个表的交集fulljoin,结果集取两个表的并集mysql没有fulljoin,union取代union与unionall的区别为,union会去重crossjoin笛卡尔积如果不使用where条件则结果集为两个关联表行的乘积与,的区别为,crossjoin建立结果集时会根据on条件过

mysql的join查询和多次查询方法是什么mysql的join查询和多次查询方法是什么Jun 02, 2023 pm 04:29 PM

join查询和多次查询比较MySQL多表关联查询效率高点还是多次单表查询效率高?在数据量不够大的时候,用join没有问题,但是一般都会拉到service层上去做第一:单机数据库计算资源很贵,数据库同时要服务写和读,都需要消耗CPU,为了能让数据库的吞吐变得更高,而业务又不在乎那几百微妙到毫秒级的延时差距,业务会把更多计算放到service层做,毕竟计算资源很好水平扩展,数据库很难啊,所以大多数业务会把纯计算操作放到service层做,而将数据库当成一种带事务能力的kv系统来使用,这是一种重业务,

MySQL中JOIN怎么用MySQL中JOIN怎么用Jun 03, 2023 am 09:30 AM

简介A的独有+AB的公有B的独有+AB的公有AB的公有A的独有B的独有A的独有+B的独有+AB的公有A的独有+B的独有练习建表部门表DROPTABLEIFEXISTS`dept`;CREATETABLE`dept`(`dept_id`int(11)NOTNULLAUTO_INCREMENT,`dept_name`varchar(30)DEFAULTNULL,`dept_number`int(11)DEFAULTNULL,PRIMARYKEY(`dept_id`))ENGINE=InnoDBAUT

利用MySQL的JOIN函数进行表的连接操作利用MySQL的JOIN函数进行表的连接操作Jul 26, 2023 am 08:37 AM

利用MySQL的JOIN函数进行表的连接操作在MySQL中,JOIN是一种非常常用的操作,它允许我们将两个或多个表根据它们之间的关联字段进行连接。这样可以方便地从多个表中查询和获取相关数据,提高查询效率和灵活性。本文将使用代码示例演示如何利用MySQL的JOIN函数进行表的连接操作。先创建两个示例表:students和scores。students表包含学生

MySQL中join语句如何优化MySQL中join语句如何优化Jun 03, 2023 am 09:31 AM

SimpleNested-LoopJoin我们来看一下当进行join操作时,mysql是如何工作的。常见的join方式有哪些?如图,当我们进行连接操作时,左边的表是驱动表,右边的表是被驱动表SimpleNested-LoopJoin这种连接操作是从驱动表中取出一条记录然后逐条匹配被驱动表的记录,如果条件匹配则将结果返回。然后接着取驱动表的下一条记录进行匹配,直到驱动表的数据全都匹配完毕因为每次从驱动表取数据比较耗时,所以MySQL并没有采用这种算法来进行连接操作BlockNested-LoopJ

如何通过MySQL对JOIN优化来提高性能如何通过MySQL对JOIN优化来提高性能May 11, 2023 am 08:48 AM

在大多数的Web应用中,数据库操作是最基本也是最重要的一环。而MySQL作为目前最常用的关系型数据库管理系统,在承载了无数网站和应用的同时,也面临着越来越大规模的数据处理和查询访问压力。在这种背景下,性能优化成为了MySQL数据库管理的一个重要环节,而JOIN操作是其中的一个关键点。JOIN连接是MySQL中最常用的数据查询语句之一。在

使用PHP join()函数将数组转换为字符串使用PHP join()函数将数组转换为字符串Jun 26, 2023 pm 11:18 PM

PHP是一种常用的服务器端脚本语言,它拥有许多有用的函数,其中之一就是join()函数。它可以将一个数组转换为一个字符串,本文将详细介绍如何使用PHPjoin()函数将数组转换为字符串。一、什么是PHPjoin()函数?join()函数也称为implode()函数,是PHP中将数组转换为字符串的方法之一。它的作用是将数组中的元素连接起来形成一个字符串,可

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),