亲高手看看一个多表查询的问题
数据表activity 中有字段 ac_id ac_title openid 等字段
数据表 apply 中有ap_id ac_id(既activity表中的ac_id) openid 等字段
现在需要先查出apply中有 符合用户的openid的字段 然后 再查询出 apply表中ac_id等于activity表中ac_id的数据集
<code>query("select * from activity,apply where apply.ac_id=activity.ac_id order by ap_id desc");</code>
这样的语句只能查询出 apply表中ac_id等于activity表中ac_id的数据集 但是不知道怎么查出 apply中openid等于用户openid的数据 所以 业务开发的时候不能区分开始那个用户的 跪求大神提出解决方案 小弟是新手
回复内容:
数据表activity 中有字段 ac_id ac_title openid 等字段
数据表 apply 中有ap_id ac_id(既activity表中的ac_id) openid 等字段
现在需要先查出apply中有 符合用户的openid的字段 然后 再查询出 apply表中ac_id等于activity表中ac_id的数据集
<code>query("select * from activity,apply where apply.ac_id=activity.ac_id order by ap_id desc");</code>
这样的语句只能查询出 apply表中ac_id等于activity表中ac_id的数据集 但是不知道怎么查出 apply中openid等于用户openid的数据 所以 业务开发的时候不能区分开始那个用户的 跪求大神提出解决方案 小弟是新手
只要在 sql 中加上 openid 的条件不就行了,就是如下加上 and openid='xxx'
<code>select * from activity,apply where apply.ac_id=activity.ac_id and apply.openid='xxx' order by ap_id desc</code>
假设目前要搜索的用户的openid = 2,你的意思是:
1.从数据表activity中搜出openid == 2的数据,作为数据集1.
2.对于数据集1中的数据,在数据表apply中查出apply.ac_id == 数据集1.ac_id 的数据?
左连接怎么样亲
select * from activity as ac left join apply as ap on ac.ac_id = ap.ac_id where openid = "xxxxx"

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
