以下のクエリを実行すると、エラーではなく返り値が空になります。なぜでしょうか?
WHERE以降の条件にあてはまるレコードは複数存在しているのですが、何もあてはまりません。
掲示板のようなものなのですが、PHPのプログラム上では投稿がゼロに、phpMyAdminでこのクエリを直接入れると返り値が空です。
関係ない部分も多いかもしれませんが、クエリ全文を載せます。
SQL
1SELECT 2tw_timeline.number, 3tw_timeline.id, 4tw_timeline.comment, 5tw_timeline.date, 6tw_timeline.replyto, 7tw_timeline.replyfrom, 8tw_timeline.quote_from, 9tw_account_detail.name, 10tw_account_detail.filename, 11quote_replyfrom.id AS quote_id, 12quote_replyfrom.comment AS quote_comment, 13quote_replyfrom.date AS quote_date, 14quote_quote_from.id AS quote_id, 15quote_quote_from.comment AS quote_comment, 16quote_quote_from.date AS quote_date, 17quote_detail.name AS quote_name, 18quote_detail.filename AS quote_filename 19FROM tw_timeline JOIN tw_account_detail ON tw_timeline.id = tw_account_detail.id 20JOIN tw_timeline AS quote_replyfrom ON quote_replyfrom.number = tw_timeline.replyfrom 21JOIN tw_timeline AS quote_quote_from ON quote_quote_from.number = tw_timeline.quote_from 22JOIN tw_account_detail AS quote_detail ON quote_detail.id = tw_timeline.id 23WHERE tw_timeline.id = 1 OR tw_timeline.id = 9 OR tw_timeline.id = 10 OR 24tw_timeline.id = 4 OR tw_timeline.id = 2 OR tw_timeline.id = 3 25ORDER BY tw_timeline.date DESC
tw_timeline(掲示板の投稿内容一覧)というテーブルがありまして、tw_account_detailというのは投稿者の名前などを格納するテーブルです。
同じtw_timelineおよびtw_account_detailのテーブルを2回ずつJOINしているのは、=の右の数値を条件に別の数値を取り出したいためです。
tw_timelineには以下のカラムが、
number
, id
, comment
, date
, replyto
, replyfrom
, quote_from
tw_account_detailには以下のカラムがあります。
id
, name
, prof
, place
, filename
, created_date
, updated_date
例えば各テーブルの1レコード目は以下のようなデータがあります。
tw_timeline
number
id
comment
date
replyto
replyfrom
quote_from
1
3
あいうえおあいうえおあいうえおあいうえおあいうえおあいうえおあいうえお
2016-07-25 17:29:25
0
0
0
tw_account_detail
id
name
prof
place
filename
created_date
updated_date
1
ひろし
ひろしの自己紹介2
東京2
e371bda7e8f2c361cb62978106696603.jpg
2016-09-19 05:01:36
NULL
回答5件
あなたの回答
tips
プレビュー