使用和从mysql获取记录 [英] get records from mysql using and

查看:84
本文介绍了使用和从mysql获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mysql中我有记录为







hotelid amenitieid

31534 719

31534 665

31534 603

31534 663

31534 1993

31534 638

31124 719

14744 719

25363 665

12523 603

17458 665





并且想要hotelid,其中amenitieid = 719和amenitieid = 603(两者都在那里)

来自以上数据库字段值



什么是mysql查询此

解决方案

尝试:

  SELECT  *  FROM  MyTable  WHERE  amenitieid = 719  amenitieid = 603 





错字 - AND为OR [/ edit]


< blockquote>你可以添加一个去规范化的表,为每个amenityid添加hotelid和boolean列,并在该表中执行搜索。

但是确保当原始表中的数据发生变化时(例如使用触发器),该表会自动更新。


In mysql i have records as



hotelid amenitieid
31534 719
31534 665
31534 603
31534 663
31534 1993
31534 638
31124 719
14744 719
25363 665
12523 603
17458 665


and want hotelid where amenitieid=719 and amenitieid=603 (both are there)
from above database field values

what is mysql query for this

解决方案

Try:

SELECT * FROM MyTable WHERE amenitieid=719 OR amenitieid=603



[edit]Typo - AND for OR[/edit]


You could add a de-normalized table, having the hotelid and a boolean column for each amenityid, and perform the search in that table.
But then make sure that that table is updated automatically when the data in the original tables change (e.g. using triggers).


这篇关于使用和从mysql获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆