之前可能会问过,但我的问题可能更复杂。
我正在使用OpenCart数据库,需要更新类别的图像。图像名称与类别名称相同,只是小写并附加' .jpg'。问题是,我只想更新特定条目,即某个父ID内的条目。
获取相关类别ID的我的SELECT是:
SELECT c.category_id FROM oc23_category c LEFT JOIN oc23_category_description cd ON cd.category_id = c.category_id WHERE c.parent_id = 71
所以我尝试使用这个SELECT
语句来引用更新图像的位置:
UPDATE oc23_category SET image = LOWER(oc23_category_description.name) WHERE category_id IN(SELECT c.category_id FROM oc23_category c LEFT JOIN oc23_category_description cd ON cd.category_id = c.category_id WHERE c.parent_id = 71);
但我得到的错误是:
您无法指定目标表' oc23_category'用于在FROM中更新 条款
我不确定这意味着什么或如何纠正它。感谢您的任何帮助,谢谢。
答案 0 :(得分:1)
使用join代替子查询
export class RestResource {
static readonly LOADING: string = 'RestResource_Loading';
static readonly ERROR: string = 'RestResource_Error';
static readonly IDLE: string = 'RestResource_Idle';
public value: Observable<any>;
public status: Observable<string>;
private loadStatus: Observer<any>;
private reloader: Observable<any>;
private reloadTrigger: Observer<any>;
constructor(requestObservableFn: () => Observable<any>) {
this.status = Observable.create((o) => {
this.loadStatus = o;
});
this.reloader = Observable.create((o: Observer<any>) => {
this.reloadTrigger = o;
});
this.value = this.reloader.startWith(null).switchMap(() => {
if (this.loadStatus) {
this.loadStatus.next(RestResource.LOADING);
}
return requestObservableFn()
.map((res) => {
if (this.loadStatus) {
this.loadStatus.next(RestResource.IDLE);
}
return res;
}).catch((err)=>{
if (this.loadStatus) {
this.loadStatus.next(RestResource.ERROR);
}
return Observable.of(null);
});
}).publishReplay(1).refCount();
}
reload() {
this.reloadTrigger.next(null);
}
}