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;";

ユニオン 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


どんな助けでも大歓迎です。前もって感謝します!!!

4

0 に答える 0