F
F
freelion932019-09-17 16:25:22
MySQL
freelion93, 2019-09-17 16:25:22

How to compose a SQL LIKE query to select before the slash character?

I'm trying to make a request to select files for a given directory of the form files/directory/sub_directory
Accordingly, if I make a request for the files/ root folder, then everything is needed until the next slash, for example:

  • files/styles.css
  • files/index.php
  • files/js
  • files/src

If I write an expression: then I get, in addition to the above, internal files from folders too:
SELECT * FROM files WHERE path LIKE 'files/%';
  • files/src/ajaxcontr.php
  • files/src/dbcontr.php
  • files/js/diagram.js
  • files/js/manage.js

How to get only those that include anything but until the next slash
if I request the root then files/anything here
or if I request a sub directory, then files/directory/anything here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2019-09-17
@freelion93

WHERE `path` REGEXP '^files/[^/]*$'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question