MySQL比较两个表中的列和WHERE X =“%%”

时间:2017-02-14 10:29:05

标签: mysql sql

我正在尝试编写一个MySQL查询来比较两个表中的列,并为其他条件添加WHERE。

我希望我尝试做的例子会有所帮助。

SELECT `practice-name`, `practice-address-4`, `practice-address-5`, `practice-bnf-name` 
FROM `practice-information` 
JOIN `practice-prescribing` 
WHERE `practice-information.practice-number` = `practice-prescribing.practice-number` AND 
      `practice-name` LIKE "%%" OR `practice-address-4` LIKE "%%" OR
      `practice-address-5` LIKE "%%" OR `practice-bnf-name` LIKE "%%" 
LIMIT 0, 5

1 个答案:

答案 0 :(得分:0)

SELECT 
    `practice-name`, 
    `practice-address-4`, 
    `practice-address-5`, 
    `practice-bnf-name` 
FROM `practice-information` 
JOIN `practice-prescribing` ON `practice-information`.`practice-number` = `practice-prescribing`.`practice-number`
WHERE 
    `practice-name` LIKE "%PUT STUFF HERE%" OR 
    `practice-address-4` LIKE "%PUT STUFF HERE%" OR
    `practice-address-5` LIKE "%PUT STUFF HERE%" OR 
    `practice-bnf-name` LIKE "%PUT STUFF HERE%" 
LIMIT 0, 5