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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:47:57+00:00 2026-05-15T16:47:57+00:00

I need to populate a currently empty table with a hundred or so fake

  • 0

I need to populate a currently empty table with a hundred or so fake records to simulate logins over the past two years to test my code with.

The login table schema looks like:

CREATE TABLE `Logins` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `User_ID` int(11) NOT NULL,
  `Date_Login` datetime NOT NULL,
  `Location` enum('site','admin') NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I really am new at SQL in general, so, I don’t have the slightest idea what the query should look like past

INSERT INTO `Logins` (`User_ID`,`Date_Login`,`Location`) VALUES ...

What I need is insert N entries (lets say 100) into Logins so that

  • User_ID draws its values from the Users table’s ID field
  • Date_Login should be between 2 years ago and now
  • Location should alternate between 'site' and 'admin', but with 'site' more heavily weighted (say 80% of the time).

Hopefully, I can glean some SQL-fu to help with similar problems in the future 😀

Thanks!

(I’m using MySQL 5.1)

  • 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-15T16:47:58+00:00Added an answer on May 15, 2026 at 4:47 pm

    Here is an SQL statement to insert a single row into the Logins table. You can run this repeatedly (e.g. in a stored procedure) to get multiple records. You have to run it multiple times to get multiple records because if you increase LIMIT 1 to LIMIT 10 you will get 10 records but the User_ID values will be the same for each record.

    INSERT INTO `Logins` (`User_ID`, `Date_Login`, `Location`)
    SELECT
      users.ID AS `User_ID`,
      DATE_SUB(NOW(), INTERVAL FLOOR(1 + (RAND() * (365 * 2))) DAY) AS `Date_Login`,
      IF(RAND() > 0.8, 'admin', 'site') AS `Location`
    FROM users
    ORDER BY RAND()
    LIMIT 1;
    

    Normally ORDER BY RAND() is bad style because it is inefficient, but this isn’t a performance-sensitive task.

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

Sidebar

Related Questions

I have to pre-populate two calendars with values. I need it to be in
I need to populate the currently scheduled tasks in task scheduler 2.0 to a
I need to populate a table that will store the date ranges between 2
I currently have several if statements that populate a specific table after the button
I have 2 tables: publications and books. Currently, the table publications is empty. I
I need to populate a .net DataGridView from a collection physically (without data binding)
I have a livesearch script that i need to populate my html menu with
I ve data in the JSON format given below,need to populate the slick grid
I need to create and populate a ListView with 3 strings that come from
i need run code that will create a database and populate tables. i am

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.