Adam
Adam

Reputation: 20952

MySQL multiple CHAR_LENGTH()

I would like to run an SQL SELECT that returns rows where the match and profile fields total more then 300 characters. I've tried line below but it doesn't work - how can chat length be added to make a total and only allow over a certain limit.

SELECT match,profile FROM matches WHERE SUM (CHAR_LENGTH(match),CHAR_LENGTH(profile)) > 300;

thankyou

Upvotes: 0

Views: 562

Answers (2)

Wyzard
Wyzard

Reputation: 34581

SUM is an aggregate function, used for adding values in the same column across multiple rows. To add values in different columns of a single row, just use +.

Upvotes: 1

Joseph B
Joseph B

Reputation: 5669

You can try:

SELECT match, profile 
FROM matches 
WHERE CHAR_LENGTH(match) + CHAR_LENGTH(profile) > 300;

Upvotes: 2

Related Questions