Home Backend Development PHP Tutorial 求一将mysql一数据库下多表循环合并查询语句?该怎么处理

求一将mysql一数据库下多表循环合并查询语句?该怎么处理

Jun 13, 2016 pm 01:46 PM
default NOT null quot select

求一将mysql一数据库下多表循环合并查询语句?
$str="SELECT * FROM talbe having ( 姓名 like '%奥巴马%'||职业 like '%政治家%') limit ".($page-1)*$num."


PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$conn=@mysql_connect("localhost","root","123456","test");//连接test数据库后,如何将test下的各个表合并查询输出结果?

貌似
for(...){//循环求出表名
....
tableabcxyz= talbe1,talbe2,...talbe3
}

$str="SELECT * FROM talbeabcxyz having ( 职业 like  '%医生%') limit ".($page-1)*$num."

....


Copy after login


求解。



------解决方案--------------------
每张表建立外键,可将所有表链接起来查询。
如:表1:
CREATE TABLE `mis_link` (
`lid` int(6) NOT NULL,
`cid` int(6) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
表2:
CREATE TABLE `mis_commodity` (
`cid` int(6) NOT NULL auto_increment,
`comName` varchar(20) NOT NULL,
`comPrice` varchar(20) NOT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
表3:
CREATE TABLE `mis_order` (
`oid` int(6) NOT NULL auto_increment,
`sid` int(6) NOT NULL,
`cid` int(6) NOT NULL,
`ordTime` varchar(20) NOT NULL default '',
`ordPrice` varchar(20) NOT NULL default '',
PRIMARY KEY (`oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

SQL code

select o.oid,l.lid,c.cid,comName,comPrice,ordTime
from mis_order o,mis_link l,mis_commodity c
where o.oid=l.lid and c.cid=l.cid;
<br><font color="#e78608">------解决方案--------------------</font><br>talbe 就没懂啥意思...table就有点明白了...<br><br>select name from table1 where name like "obama%"<br>union<br>select name from table2 where name like "obama%"<br><br><br>尝试使用union操作,但注意select出来的列数必须一致,不一致的可以用null补充
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
可以改成 以下吗?
1. [表名2名称的缩写]改成 直接用 [表名2];
2. 去掉form后面的 as和缩写名称;为什么要加as和缩写名称呢?
3.where后是我想要的条件:
如:

select [表名1].表1字段,[表名2].表2字段,[表名3].表3字段,……
from [表1名], [表2名], ……
having ( 职业 like '%医生%'||其他 like '%医生%') limit ".($page-1)*$num.",".$num;
Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
What do undefined and null mean? What do undefined and null mean? Nov 20, 2023 pm 02:39 PM

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

What is the difference between null and NULL in c language What is the difference between null and NULL in c language Sep 22, 2023 am 11:48 AM

The difference between null and NULL in C language is: null is a macro definition in C language, usually used to represent a null pointer, which can be used to initialize pointer variables, or to determine whether the pointer is null in a conditional statement; NULL is a macro definition in C language A predefined constant in , usually used to represent a null value, used to represent a null pointer, null pointer array or null structure pointer.

How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

What is the difference between null and undefined What is the difference between null and undefined Nov 08, 2023 pm 04:43 PM

The difference between null and undefined is: 1. Semantic meaning; 2. Usage scenarios; 3. Comparison with other values; 4. Relationship with global variables; 5. Relationship with function parameters; 6. Nullability check; 7. Performance considerations; 8. Performance in JSON serialization; 9. Relationship with types. Detailed introduction: 1. Semantic meaning, null usually means knowing that this variable will not have any valid object value, while undefined usually means that the variable has not been assigned a value, or the object does not have this attribute; 2. Usage scenarios, etc.

When to use null and undefined When to use null and undefined Nov 13, 2023 pm 02:11 PM

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

Configure default gateway Configure default gateway Dec 07, 2023 pm 03:02 PM

Steps to configure default gateway: 1. Open the control panel; 2. Select Network and Internet; 3. Configure network connection; 4. Configure IP address; 5. Configure DNS server address; 6. Confirm the configuration; 7. Restart the network device. Detailed introduction: 1. Open the Control Panel, in Windows system, click the Start menu, select "Control Panel"; 2. Select Network and Internet, in the Control Panel, select "Network and Internet"; 3. Configure network connections, etc. .

See all articles