How can I validate user input from two fields even when the user swipe the fields data

I have this sql query to check whether it exist in the database. I want it to check the database if that data exist.

SELECT * FROM tbl_merge WHERE school_id1=? AND groupno1=? AND school_id2=? AND groupno2=? AND session=?

I want the query to swipe the input from user and also check as follows:

SELECT * FROM tbl_merge WHERE school_id2=? AND groupno2=? AND school_id1=? AND groupno1=? AND session=?

to be more specific, I want the query to check for:

where the user input will only be

<input type="text" name="school_id1">
<input type="text" name="groupno1">
<input type="text" name="school_id2">
<input type="text" name="groupno2">

thank you.