0

I have this table:

==========================
id            name       
--------------------------
1             telephone
2             microphone
3             media
4             phone

I'm using findByNameContainingIgnoreCase(String letter) to get the data that contains the substring (pho). The results are:

==========================
    id            name       
    --------------------------
    1             telephone
    2             microphone
    4             phone

But I want to also sort the output using the substring in the autosuggesting order. Like this:

 ==========================
    id            name       
    --------------------------
    4             phone
    1             telephone
    2             microphone

Does anyone know how to help?

0

1 Answer 1

4

You can use position() for that and order by it

select * from your_table
where position('pho', name) > 0
order by position('pho', name) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.