简体   繁体   中英

Select records beginning with defined symbol from database

I have this code:

$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') . "'");

and database table:

manufacturer_id | name | image | sort_order

How can I get all records begining with symbol "B" or with "9" in column name ?

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

The SQL looks like:

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%')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM