我有一個MySQL數據庫與幾個表。他們是這個樣子 -如何在查詢FNF後的兩個表時獲得一行結果?
食物表:
+----------+------------+--------------+
| username | date | food |
+----------+------------+--------------+
| test123 | 2012-09-16 | rice |
| test123 | 2012-09-16 | pizza |
| test123 | 2012-09-16 | french fries |
| test123 | 2012-09-16 | burger |
+----------+------------+--------------+
主表:
+----------+------------+----------------+---------------+-------------+-------------+
| username | date | water_quantity | water_chilled | smoked_what | smoke_count |
+----------+------------+----------------+---------------+-------------+-------------+
| test123 | 2012-09-16 | 1 | no | cigarettes | 20 |
+----------+------------+----------------+---------------+-------------+-------------+
當我使用查詢SELECT * FROM main,food WHERE main.date=food.date;
,我得到四行結果。我如何才能在單行中得到結果?最終,當我將結果編碼爲JSON時,我希望它看起來像這樣 -
[
{
"username":"test123",
"date":"2012-09-16",
"water_quantity":"1",
"water_chilled":"no",
"smoked_what":"cigarettes",
"smoke_count":"20",
{
"food":"rice",
"food":"pizza",
"food":"french fries",
"food":"burger",
},
}
]
或類似的東西。我是MySQL和數據庫的新手,一般也是JSON。在此先感謝您的幫助。
你想要得到單行上的所有四個好記錄,這是你的問題嗎? –
@MoyedAnsari是的...... –