Can you tell me how to get these three user names by linking them in a table with three different user ids?

  mysql, question


The general scenario is this: I have an app table

SQL code
 `id` int(10) unsigned NOT NULL auto_increment,
 `appname`varchar (100) not null comment 'appname',
 `appenname`varchar (50) not null comment 'appname initials',
 `tid`medical (5) not null comment 'app classification',
 `uid`int (11) not null comment' business manager',
 "manager` int(11) NOT NULL COMMENT' channel manager',
 `channel _ id`int (11) not null default' 0' comment' marketing channels',
 `reference`varchar (30) not null comment 'app source',
 `package _ name`varchar (255) not null comment 'app package name',
 `juwan _ id`int (11) not null default' 0' comment' get together to play appid',
 `downloadurl`varchar (255) not null comment' app download path',
 Commission 'enum ('1',' 2') not null comment' commission type: 1,CPA;  2:CPS',
 Commission val`decimal (8,2) unsigned not null default' 0.00' comment' commission value',
 `size`decimal (10,3) not null comment' size',
 `system`enum ('1',' 2') not null default' 1' comment' system requirements: 1,android;  2,ios',
 `sort`int (11) not null default' 0' comment' sort',
 `details`varchar (500) not null comment' details',
 `edituptime`int (11) not null comment' update time',
 `appuptime`int (11) not null comment' app installation package update time',
 `flag`TINYINT (1) not null comment' app status: 0, not on shelves;  1, shelves;  2. Get off the rack',
 PRIMARY KEY  (`id`),
 KEY `app_enname` (`appenname`)
 ) engine = MYISAM defaultcharset = utf8comment =' app management table' AUTO_INCREMENT=13;
 And user tables:
 SQL code
 `uid` int(11) NOT NULL auto_increment,
 `username` varchar(50) default NULL,
 `password` varchar(50) default NULL,
 `Group`TINYINT (2) Default Null Comment' User Group',
 `manager`int (11) defaultnull comment' channel manager',
 `AccountType`TINYINT (2) Default Null Comment' Account Attribute',
 `realname`varchar (50) defaultnull comment 'real name',
 `telephone`bigint (12) default null comment' landline',
 `mobilephone`bigint (12) defaultnull comment 'mobilephone',
 `qq`int (11) defaultnull comment 'qq number',
 `company _ name`varchar (100) defaultnull comment' company name',
 `company _ simple _ name`varchar (20) defaultnull comment' short for company',
 `company _ address`varchar (100) defaultnull comment' correspondence address',
 `company _ zip code`int (7) defaultnull comment' zip code',
 `bank _ name`varchar (100) defaultnull comment' bank of account',
 `bank _ address`varchar (100) defaultnull comment' bank address',
 `bank _ account`varchar (50) defaultnull comment' bank account',
 `bank _ username`varchar (50) defaultnull comment' account opening name',
 PRIMARY KEY  (`uid`)

I now want to take out all the data in the app table and the userNAME or realname in the USER table corresponding to uid, manager, and channel_id in the form of linked tables.

How should this be realized, or how should the watch design be changed?

First of all, there is room for optimization in the design of your current two tables.
Ch_app table, fields such as details take up a lot of disk space, but the probability of using these fields in query is not high. You can consider grouping these fields into tables to reduce disk io, which is helpful to improve query efficiency.

Ch_user table, you can also split into two tables, assuming that some fields in the table will not be used frequently.

The above way of dividing tables can obviously improve the efficiency of sql query, of course increasing the complexity in business.

Secondly, my personal habit is to avoid using related queries as much as possible, such as finding app table data in your topic and querying user information through uid
You can find out uid and query the user information separately in the program inside.
The advantage of this is that when you need to extend, such as using redis memchaced, you don’t need to make too many changes to the existing code.
The cache hit rate is also high.
In short, I personally recommend separate inquiries