我在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) UserNote :User_UserId,Note_NoteId,Issue_IssueId
3)用户:UserId,UserName,UserShortCode
4)审核:AuditId,AuditNote,Issue_IssueId,User_UserId,AuditTimeStamp
5)问题:IssueId,ProjectFile_FileId
任何帮助都会受到赞赏。在此先感谢!!!