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 77409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:49:33+00:00 2026-05-10T20:49:33+00:00

I have a database with one table, like so: UserID (int), MovieID (int), Rating

  • 0

I have a database with one table, like so:

UserID (int), MovieID (int), Rating (real) 

The userIDs and movieIDs are large numbers, but my database only has a sample of the many possible values (4000 unique users, and 3000 unique movies)

I am going to do a matrix SVD (singular value decomposition) on it, so I want to return this database as an ordered array. Basically, I want to return each user in order, and for each user, return each movie in order, and then return the rating for that user, movie pair, or null if that user did not rate that particular movie. example:

USERID | MOVIEID | RATING ------------------------- 99835   8847874    4 99835   8994385    3 99835   9001934    null 99835   3235524    2            .            .            . 109834  8847874    null 109834  8994385    1 109834  9001934    null  etc 

This way, I can simply read these results into a two dimensional array, suitable for my SVD algorithm. (Any other suggestions for getting a database of info into a simple two dimensional array of floats would be appreciated)

It is important that this be returned in order so that when I get my two dimensional array back, I will be able to re-map the values to the respective users and movies to do my analysis.

  • 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. 2026-05-10T20:49:33+00:00Added an answer on May 10, 2026 at 8:49 pm
    SELECT m.UserID, m.MovieID, r.Rating     FROM (SELECT a.userid, b.movieid               FROM (SELECT DISTINCT UserID FROM Ratings) AS a,                    (SELECT DISTINCT MovieID FROM Ratings) AS b          ) AS m LEFT OUTER JOIN Ratings AS r          ON (m.MovieID = r.MovieID AND m.UserID = r.UserID)     ORDER BY m.UserID, m.MovieID; 

    Now tested and it seems to work!

    The concept is to create the cartesian product of the list of UserID values in the Ratings table with the list of MovieID values in the Ratings table (ouch!), and then do an outer join of that complete matrix with the Ratings table (again) to collect the ratings values.

    This is NOT efficient.

    It might be effective.

    You might do better though to just run the plain simple select of the data, and arrange to populate the arrays as the data arrives. If you have many thousands of users and movies, you are going to be returning many millions of rows, but most of them are going to have nulls. You should treat the incoming data as a description of a sparse matrix, and first set the matrix in the program to all zeroes (or other default value), and then read the stream from the database and set just the rows that were actually present.

    That query is the basically trivial:

    SELECT UserID, MovieID, Rating     FROM Ratings     ORDER BY UserID, MovieID; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with a large number of rows and one numeric
I have a SQL Mobile database with one table. It has several columns with
I have a database table and one of the fields (not the primary key)
Many applications have grids that display data from a database table one page at
If I have a class representing access to one table in my database in
In one of my applications I have a 1gb database table that is used
In my database, in one of the table I have a GUID column with
I have several tables in a database. One table (tbl_transactions) has thousands of orphaned
I have a database with 2 tables. One of the tables holds a row
In my database, I have a few columns in one of my tables that

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.