I would like to know how can I do joints in this case :
I have a table named : Table_ref
that contains the name of all the table in the database, with the structure :
-----------------------------------------------
| Field | Type | Null | Key |
-----------------------------------------------
| tbl_name | varchar(45) | NO | PRI |
| tbl_type | Tinyint(3) | NO | MUL |
-----------------------------------------------
and forteen other table with names like : A1
, B1
, A2
, B2
... with the same structure :
-----------------------------------------------
| Field | Type | Null | Key |
-----------------------------------------------
| id | int(10) | NO | PRI |
| itime | int(10) | YES | MUL |
| dtime | int(10) | YES | MUL |
| src | varchar(40) | YES | |
| dstname | varchar(255)| YES | |
-----------------------------------------------
The question is how can I do joints in order to extract information where src='192.168.1.2'
from all the tables.
This is the combined structure for all your tables
-----------------------------------------------
| Field | Type | Null | Key |
-----------------------------------------------
| id | int(10) | NO | PRI |
| itime | int(10) | YES | MUL |
| dtime | int(10) | YES | MUL |
| src | varchar(40) | YES | |
| dstname | varchar(255)| YES | |
| type | Tinyint(3) | NO | MUL |
-----------------------------------------------
And now you can extract information with a simplist query
SELECT
*
FROM mytable
WHERE src = '192.168.1.2'
It will fetch records from every type. If you need information form specific type just add another where condition
SELECT
*
FROM mytable
WHERE src = '192.168.1.2'
AND type = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.