Are you sure you want to merge multiple tables in a mysql database cyclically? $ Str & quot; SELECT * FROMtalbehaving (name like % Obama % | occupation like % politician %) limit & quot ;. ($ page-1) * $ num. & quot; PHPcode $ conn @ mysql_connect (& quot; localhos: query statement for combining multiple tables in a mysql database cyclically?
$ Str = "SELECT * FROM talbe having (name like '% Obama %' | occupation like '% politician %') limit ". ($ page-1) * $ num."
PHP code
$ Conn = @ mysql_connect ("localhost", "root", "123456", "test"); // after connecting to the test database, how can I merge the tables under test and query the output results? Looks like (...) {// cyclically obtain the table name .... tableabcxyz = talbe1, talbe2 ,... talbe3} $ str = "SELECT * FROM talbeabcxyz having (occupation like '% doctor %') limit ". ($ page-1) * $ num. "....
.
------ Solution --------------------
A foreign key is created for each table, and all tables can be linked for query.
For example, Table 1:
Create table 'mis _ link '(
'Lid' int (6) not null,
'CID' int (6) NOT NULL
) ENGINE = InnoDB default charset = utf8;
Table 2:
Create table 'mis _ commodity '(
'CID' int (6) not null auto_increment,
'Comname' varchar (20) not null,
'Company' varchar (20) not null,
Primary key ('CID ')
) ENGINE = InnoDB default charset = utf8;
Table 3:
Create table 'mis _ order '(
'Id' 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 ('id ')
) ENGINE = InnoDB default charset = utf8;
SQL code
Select o. oid, l. lid, c. cid, comName, comPrice, ordTimefrom mis_order o, mis_link l, mis_commodity cwhere o. oid = l. lid and c. cid = l. cid;
------ Solution --------------------
Talbe doesn't understand what it means... table just understands...
Select name from table1 where name like "obama %"
Union
Select name from table2 where name like "obama %"
Try the union operation, but note that the columns in the select statement must be consistent. If the columns are inconsistent, null can be used to add the columns.
------ Solution --------------------
Discussion
Can I change it to the following?
1. change [abbreviation of table name 2] to [table name 2].
2. remove the as and abbreviation names after form. why should we add the as and abbreviation names?
3. After where is the condition I want:
For example:
Select [table name 1]. Table 1 field, [table name 2]. Table 2 field, [table name 3]. Table 3 field ,......
From [Table 1], [Table 2],...
Having (occupation like '% doctor %' | other like '% doctor %') limit ". ($ page-1) * $ num.", ". $ num;