Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:47:47+00:00 2026-05-28T02:47:47+00:00

This is an example version of my current SQL query: SELECT DISTINCT files.* FROM

  • 0

This is an “example version” of my current SQL query:

SELECT DISTINCT files.* FROM vw_files files
LEFT JOIN tbl_file_ext fext
ON files.id = fext.fileID
INNER JOIN tbl_extensions ext ON fext.extensionID = ext.id
WHERE ext.extension = 'exe' OR ext.extension = 'com'

The WHERE clause is driven by a user entering a comma delimited string.

What I’d like is to order/group by the input so say if a user enters:

com, exe, jpg the WHERE clause will be:

WHERE ext.extension = 'com' OR ext.extension = 'exe' OR ext.extension = 'jpg'

The results need to be ordered by priority of the inputs something like:

File1 com exe jpg
File2 com exe jpg
File3 com exe
File4 com jpg
File5 com

The WHERE clause is constructed via PHP, but how can I construct a ORDER or GROUP clause which will retuern results ordered by priority of the usrs inputs.

Edit as requested —-

The above was just an example as I stated, and didn’t feel appropriate as i’m doing something similar to stackoverflow. However, the real setup is as follows:

tbl_solutions –
id, authorID, ipAddress, title, question, dateAdded, locked, active

tbl_solution_tags –
id, FK solutionID, FK tagID

tbl_solution_files –
id, FK solutionID, FK fileID

vw_solution_and_file –
username, id (solution id), authorID, ipAddress, title, question, dateAdded, locked, active, fileName, fileSize, removed, public

select sol.*, files.fileName, files.fileSize, files.removed, files.public from 
tbl_solutions sol left join
tbl_files files on (select sf.fileID from tbl_solution_files sf
where sf.solutionID = sol.id) = files.id;

vw_solution_file_tags – same as above but also returns tags

SELECT sf.*,GROUP_CONCAT(tags.tag SEPARATOR ', ') as 'tags' FROM
vw_solution_and_file sf LEFT JOIN tbl_solution_tags st
ON sf.id = st.solutionID INNER JOIN tbl_tags tags
ON st.tagID = tags.id GROUP BY sf.id

Example output from vw_solution_file_tags:

username id authorID ipAddress title question dateAdded locked active fileName fileSize removed public tags

craig 24 81 127.0.0.1 “A Title” “A question” 2012-01-01 0 1 NULL NULL NULL 1 c++, ASP, gdb

craig 25 81 127.0.0.1 “B Title” “B question” 2012-01-01 0 1 NULL NULL NULL 1 c++, ASP, Windows

So at the moment all I’m doing is using vw_solution_file_tags in my page, however the user is going to be able to apply a filter on the tags. So he may say ASP, Windows so both results above will show. But they need to be in order of precedence of the users input.

So the code I want to use in my PHP Query will be similar to vw_solution_file_tags but only where the tags match user input and ordered by that input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:47:48+00:00Added an answer on May 28, 2026 at 2:47 am

    I think you may have to construct the ORDER BY from PHP code also. Try something like the follwoing. Note: first do it directly on MYSQL, if it works then move it into PHP.

    SELECT DISTINCT files.* FROM vw_files files
    LEFT JOIN tbl_file_ext fext
    ON files.id = fext.fileID
    INNER JOIN tbl_extensions ext ON fext.extensionID = ext.id
    WHERE ext.extension IN ('com', 'exe', 'jpg')
    ORDER BY 
        CASE 
            WHEN ext.extension = 'com' THEN 1
            WHEN ext.extension = 'exe' THEN 2
            WHEN ext.extension = 'jpg' THEN 3
        END 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This example is from php.net: <?php function Test() { static $a = 0; echo
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
Consider this example table (assuming SQL Server 2005): create table product_bill_of_materials ( parent_product_id int
INFORMIX-SQL 2.10.06E (DOS 6.22): This is one of the legacy version of isql that
This example uses a StringWriter to hold the serialized data, then calling ToString() gives
This example is simplified a bit, but in my ASP.NET web page in my
this example below works when hover event is trigered and when its not, its
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Consider this example (typical in OOP books): I have an Animal class, where each
Following this example, I can list all elements into a pdf file import pyPdf

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.