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

  • Home
  • SEARCH
  • 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 7713743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:56:58+00:00 2026-06-01T01:56:58+00:00

I know that this question has been asked several times and I’ve read all

  • 0

I know that this question has been asked several times and I’ve read all the answer but none of them seem to completely solve my problem.

I’m switching from a mySQL database to a MS Access database. In both of the case I use a php script to connect to the database and perform SQL queries.

I need to find a suitable replacement for a query I used to perform on mySQL.
I want to:

  1. perform a first query and order records alphabetically based on one of the columns
  2. construct a list of IDs which reflects the previous alphabetical order
  3. perform a second query with the IN clause applied with the IDs’ list and ordered by this list.

In mySQL I used to perform the last query this way:

SELECT name FROM users WHERE id IN ($name_ids) ORDER BY FIND_IN_SET(id,'$name_ids')

Since FIND_IN_SET is available only in mySQL and CHARINDEX and PATINDEX are not available from my php script, how can I achieve this?

I know that I could write something like:

SELECT name 
  FROM users 
 WHERE id IN ($name_ids) 
ORDER BY CASE id
           WHEN ... THEN 1 
           WHEN ... THEN 2
           WHEN ... THEN 3
           WHEN ... THEN 4
         END

but you have to consider that:

  • IDs’ list has variable length and elements because it depends on the first query
  • that list can easily contains thousands of elements

Have you got any hint on this?
Is there a way to programmatically construct the ORDER BY CASE ... WHEN ... statement?
Is there a better approach since my list of IDs can be big?

UPDATE: I perform two separated query because I need to access two different tables.
The databse it’s not very simple so I try to make an example:
Suppose I have a table which contains a list of users and a table which contains all the books that every user have in their bookshelf.

Since the dabase was designed in mySQL, for every book record I store the user_id in the books table in order to have a relationship between the user and the book.

Suppose now that I want to obtain a list of all the user that have books with a title starting with letter ‘a’ and I want to order the user based on the alphabetical oder of the books.
This is what I do:

  1. perform a first query to find all the books which start with letter ‘a’ and sort the alphabetically
  2. create a list of user_id which should reflect the alphabetical order of the book
  3. perform a query in the users table to find out the users names and sort them with the user_id list to have the required sorting by book

Hope this clarify what I need.

  • 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-06-01T01:57:00+00:00Added an answer on June 1, 2026 at 1:57 am

    It sounds like you need a JOIN…
    This should work, although it may need to be translated to Access syntax (which is apparently subtly different):

    SELECT b.name, a.title
    FROM book as a
    JOIN user as b
    ON b.id = a.userId
    WHERE SUBSTRING(LOWER(a.title), 1, 1) = 'a'
    ORDER by a.title
    

    I don’t know why you’re switching to Access, although I have heard it’s been improving in recent years. I think I’d prefer almost any other RDBMS, though. And your schema could probably stand some tweaking, from the sound of things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked several times on SO, but none of
I know that this question have been asked several times. But I can't get
I know this question has been asked several times, but I can't quite seem
I know this question has been asked multiple times but all the answers seem
First, I know this question has been asked several times before and that in
I know that this question has been asked loads of times, but I have
Hey all, I know that this question has been asked many times in this
I know this question has been asked many times. But from what I read,
I know that this question has a been asked many times, but I still
I know this question has been asked several times an I spent all day

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.