SQL
1SELECT COUNT(*) FROM (history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time, 2 sushi.name AS name, sushi.price AS price, sushi.img AS img, sushi.intro AS intro 3 FROM history INNER JOIN sushi ON (history.productid = sushi.id) 4 WHERE history.tableNumber = ? 5 UNION ALL 6 SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time, 7 dessert.name AS name, dessert.price AS price, dessert.img AS img, dessert.intro AS intro 8 FROM history INNER JOIN dessert ON (history.productid = dessert.id) 9 WHERE history.tableNumber = ?)
でエラーが出ます。全件数が欲しいのですが、修正箇所を教えてください。
使用テーブルは以下の3つになります。
どのようなエラーがでるのか記載願います。
有難うございます。
SQL query: Documentation
SELECT COUNT(*) FROM (SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time,
sushi.name AS name, sushi.price AS price, sushi.img AS img, sushi.intro AS intro
FROM history INNER JOIN sushi ON (history.productid = sushi.id)
WHERE history.tableNumber = 6
UNION ALL
SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time,
dessert.name AS name, dessert.price AS price, dessert.img AS img, dessert.intro AS intro
FROM history INNER JOIN dessert ON (history.productid = dessert.id)
WHERE history.tableNumber = 6) LIMIT 0, 30
MySQL said: Documentation
#1046 - No database selected
この様なエラーが出ています。
?の部分には6という数字を仮に入れております。
回答有難うございます。
エラー文言にあるように、データベースが選択されていないエラーになります。
どのようにSQL実行しているか分かりませんが、
①ターミナルでSQL実行しているなら、use データベース名(Sushi?)でデータベースを選択後、上記SQLを実行
②phpmyadminでSQL実行しているなら、データベースを選択後、SQLタブで実行
してみてください。
有難うございます。
SQL実行しております。ご指摘の通りsushiテーブルを選択している状態ですと機能しました。
しかしhistoryテーブルを選択している状態では実行してもエラーになります。なぜでしょうか。
またこの状態ではSQL文は正しいと言えますか。
SELECT COUNT(*) FROM (SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time,
sushi.name AS name, sushi.price AS price, sushi.img AS img, sushi.intro AS intro
FROM history INNER JOIN sushi ON (history.productid = sushi.id)
WHERE history.tableNumber = 6
UNION ALL
SELECT history.productid AS productid, history.tableNumber AS tableNumber, history.quantity AS quantity, history.time AS time,
dessert.name AS name, dessert.price AS price, dessert.img AS img, dessert.intro AS intro
FROM history INNER JOIN dessert ON (history.productid = dessert.id)
WHERE history.tableNumber = 6) AS CONT;
これで上手くいきました
回答1件
あなたの回答
tips
プレビュー