从数据库中选择以定义符号开头的记录

时间:2010-11-23 02:37:18

标签: php sql mysql

我有这段代码:

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "manufacturer m LEFT JOIN " . DB_PREFIX . "manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE m.manufacturer_id = '" . (int)$manufacturer_id . "' AND m2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

和数据库表:

manufacturer_id | name | image | sort_order

如何在列name中以符号“B”或“9”开头的所有记录?

2 个答案:

答案 0 :(得分:2)

... WHERE `name` LIKE 'B%' OR `name` LIKE '9%'

答案 1 :(得分:1)

SQL看起来像:

SELECT * FROM manufacturer m LEFT JOIN manufacturer_to_store m2s ON m.manufacturer_id = m2s.manufacturer_id 
WHERE m2s.store_id = <some store id here> 
   AND (m.name LIKE 'B%' or m.name LIKE '9%')