データベースには、作業中の 5 つのテーブルがあります。グループ連結を使用してデータベースから州の選択を開始するまで、すべてがうまく機能します。
これらは私のテーブルです:
- main_jobs
- サブジョブ
- カテゴリー
- 州
- state_job_relationship
テーブル作成のスニペット
create table if not exists category (
id int(3) not null auto_increment,
parent int(5) not null,
name varchar(255) not null,
description text,
slug varchar(255),
level int (3),
PRIMARY KEY (id, slug));
create table if not exists state (
id int(4) not null auto_increment,
country_id int(11) not null,
name varchar(255) not null,
PRIMARY KEY (id),
FOREIGN KEY (country_id) REFERENCES country (id))";
create table if not exists state_job_relationship (
id int(4) not null auto_increment,
state_id int(4) not null, FOREIGN KEY (state_id) REFERENCES state (id),
job_id int(11) not null, FOREIGN KEY (job_id) REFERENCES sub_jobs (id),
PRIMARY KEY (id));
create table if not exists main_jobs (
id int not null auto_increment, primary key(id),
company_name varchar(255),
job_title varchar(255));
create table if not exists sub_jobs (
id int not null auto_increment, primary key(id),
parent_id int(11) not null, FOREIGN KEY (parent_id) REFERENCES main_jobs (id),
title varchar(255),
description text not null,
category int (3), FOREIGN KEY (category) REFERENCES category (id)
);
これは私が選択したいものです:
サブ ジョブ テーブルの役職と、main_jobs およびカテゴリ テーブルの対応する会社名とその他の詳細。
各 sub_job が次の形式に該当する状態を選択する必要があるまで、すべてがうまく機能しました: State1、State2、State3
select sub_jobs.id as kid, main_jobs.id as parentid,
company_name, sub_jobs.description, sub_jobs.title,
job_title, category.name as ind,
DATE_FORMAT($column_date,'%a, %e %b %Y %T') as d,
(select group_concat(name seperator ', ')
from state_job_relationship, state
where job_id= kid
and state.id=state_job_relationship.state_id
group by state.id) states
from sub_jobs, category, main_jobs
where category.id=sub_jobs.category
and main_jobs.id=sub_jobs.parent_id
order by featured desc , $table.id desc
limit 100;
上記のクエリを試してみましたが、次のエラーが表示されます。
SQL 構文にエラーがあります。使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。
私は何が正しくないのですか?