0

我有以下查询PHP

$query = "Select 'NOTE' note_type, u.UserName,n.NoteId id,n.NoteText note,
                n.TimeStamp Time_Stamp,u.UserShortCode,i.IssueId,i.ProjectFile_FileId
                from Note n inner join UserNote un
                on n.NoteId = un.Note_NoteId inner join User u 
                on u.UserId = un.User_UserId
                inner join Issue i on i.IssueId = un.Issue_IssueId
                inner join Issue i2 on i.ProjectFile_FileId = i2.ProjectFile_FileId
                and i2.IssueId = ?

        union all

        SELECT 'AUDIT_NOTE' note_type,u.UserName,a.AuditId id,a.AuditNote note,
            a.AuditTimeStamp Time_Stamp,u.UserShortCode,i.IssueId,i.ProjectFile_FileId
            FROM `eoffice`.`audit` a inner join User u
            on u.UserId = a.User_UserId
            inner join Issue i on i.IssueId = a.Issue_IssueId
            inner join Issue i2 on i.ProjectFile_FileId = i2.ProjectFile_FileId
            and i2.IssueId = ?
            order by Time_Stamp asc;";

我想通过删除union all来优化查询,从而缩短它。

以下是必要的表格及其各自的字段:

1)注意:NoteId,NoteText,TimeStamp

2)用户注释: User_UserId、Note_NoteId、Issue_IssueId

3)用户:UserId、UserName、UserShortCode

4)审计:AuditId、AuditNote、Issue_IssueId、User_UserId、AuditTimeStamp

5)问题:IssueId、ProjectFile_FileId


任何帮助将不胜感激。提前致谢!!!

4

0 回答 0