English 中文(简体)
具体行文数为十。 Mysql query
原标题:Get X number of specific rows. Mysql query
  • 时间:2012-04-27 04:53:21
  •  标签:
  • php
  • mysql
  • sql

Saye 我有一个数据库,有两张表格:“食物”和“小麦”。

I query the "whatToEat" and find 3 rows:

id    Food     username
 1    Apple      John
 2    Banana     John
 3    Milk       Linda

如果我想从“食品”表中获取这些物品,我就能够做这样的想法:

SELECT * 
  FROM food 
 WHERE username= John  AND typeOfFood =  apple  
    OR typeOfFood =  Banana  OR typeOfFood =  Milk 

......但还是可以动态地写这句话,因为“ToEat”表将改变所有时间,或者我是否需要一个“食品”表,一个表格是“ToEat”中每个物体的表格?

EDIT

以上只是一个例子,真正的情景是在线游戏。 当一个参与者转向游戏时,他就把“事项——更新”摆在桌面上。 这份表格只贴上了他的名字,并贴上了配对(或者说,因为他可以同时在几个时间。) 当一个行动者收回最新情况时,我要检查他是否具备需要更新的匹配(频率“配对-更新”表),然后将数据从“配对”表中取回,而所有信息都存放在表上。

例:

The player Tim query the "mathces_updated" table and find he have 2 new matches that needs to be updated:

   match_id   username
    1          Tim
    2          Tim
    2          Lisa
    1           John
    3           John

...... 他现在希望获得有关这些配对的信息,这些信息储存在“配对”表中:

match_id   match_status player1Name Player1Score Player2Name Player2Score
   1           1           John         123         Tim          12
   2           1           Lisa          4          Tim          15
   3           1           John          0          Lisa         0
最佳回答
问题回答

我不清楚我是否正确理解这个问题。

Actually It depends on the queried tables have what in common.

如果食用食品是普通一栏,那么就提出这样的问题。

select * from food where food in (select food from whattoeat where username = ?)

如果它解决了你的问题,它就会提出疑问。

SELECT * FROM food WHERE username= John 




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签