[英]How to fetch mutiple values on select option and display in input type using ajax?
[英]How to insert using mutiple values and SELECT statements?
我想創建一個查詢來插入幾個值以及來自其他表的值,例如:
INSERT INTO table
(date, user_id, category_id, title, description)
VALUES
((STR_TO_DATE('04-01-2014', '%b-%d-%Y'),
(SELECT id FROM users WHERE username = 'admin' LIMIT 1),
(SELECT id FROM categories WHERE category = 'games' LIMIT 1),
'title here',
'description here')
但是,這給了我一個錯誤,並且從PHP出現了500個內部服務器錯誤。 請幫助。
INSERT INTO table (fields)
SELECT
str_to_date(),
users.id,
categories.id,
'title',
'description'
FROM
users
INNER JOIN
categories ON users.key = categories.key
WHERE
users.username = 'admin' AND
categories.category = 'games'
我認為應該做到的...
我很確定如果這樣做的話,您需要在VALUES
之后進行SELECT
。 試試這個,看看是否可行。
INSERT INTO table
(date, user_id, category_id, title, description)
VALUES
SELECT
STR_TO_DATE('04-01-2014', '%b-%d-%Y'),
(SELECT id FROM users WHERE username = 'admin' LIMIT 1),
(SELECT id FROM categories WHERE category = 'games' LIMIT 1),
'title here',
'description here'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.