Is there an option shorter than that?

select model, type from Product where model like '[0-9]' or model like '[0-9][0-9]' or model like '[0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or model like '[a-zA-Z]' or model like '[a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' or model like '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' 
  • one
    And what SQL dialect in question? The answer may differ for different dialects - Barmaley
  • Specify the used DBMS. And, preferably, the version ... - Akina
  • I train on this site: sql-ex.ru As for the syntax, it says: "Currently, we use Microsoft SQL Server 2017 at rating stages, and at the training stage - additional MariaDB-10.2.13 (compatible with MySQL 8), PostgreSQL 10.3 and Oracle Database 11g. Therefore, the user needs to adhere to the syntax of these implementations when writing their queries. " - Olga Climova
  • sql-ex.ru/learn_exercises.php?LN=35 - link to this task - Olga Climova

2 answers 2

As an option:

 SELECT model, type FROM product WHERE model NOT LIKE '%[^0-9]%' OR model NOT LIKE '%[^az]%' 
  • one
    Thank you for your reply! - Olga Climova

For MySQL, an option would be:

 select model, type from Product where (model regexp '^[0-9]*$') or model (model regexp '^[a-zA-Z]*$') 

PS I'm not a very big amateur / expert of the regular season - I hope colleagues will correct me

  • Swears: "Incorrect syntax near 'regexp'" - Olga Climova
  • that's all right, you have a dialect that doesn't support the regexp - Barmaley
  • Regulars can be combined into one, probably? And another model is probably superfluous. - Qwertiy
  • Yes, of course, it is possible, but I am not special in regular ones and I don’t like them at all - the answer is articulated - Barmaley