Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
835 views
in Technique[技术] by (71.8m points)

where clause - Mysql - how to use like on multiple columns

I've searched in mysql query a word in multiple column in java program. The number of column is variable. It is correct this query:

select * from customer with (city, name) like%'adelaide'%
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use CONCAT() function:

select * from customer WHERE concat(city,name) like '%adelaide%'

You can add as many columns to the concat function as you like. Also as you see I changed your like syntax, '%WORD%' and used a simple where clause.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...