Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select multiple copies of the same row?

Tags:

sql

ms-access

I have a table in MS Access with rows which have a column called "repeat"

I want to SELECT all the rows, duplicated by their "repeat" column value.

For example, if repeat is 4, then I should return 4 rows of the same values. If repeat is 1, then I should return only one row.

This is very similar to this answer:

https://stackoverflow.com/a/6608143

Except I need a solution for MS Access.

like image 701
Matthew Avatar asked Sep 02 '13 05:09

Matthew


People also ask

How do I select multiple data in a row?

Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

How do I select a row that repeats every page?

On the Page Layout tab, in the Page Setup group, click Page Setup. Under Print Titles, click in Rows to repeat at top or Columns to repeat at left and select the column or row that contains the titles you want to repeat. Click OK.


1 Answers

First create a "Numbers" table and fill it with numbers from 1 to 1000 (or up to whatever value the "Repeat" column can have):

CREATE TABLE Numbers
  ( i INT NOT NULL PRIMARY KEY
  ) ;

INSERT INTO Numbers 
  (i)
VALUES
  (1), (2), ..., (1000) ;

then you can use this:

SELECT t.*
FROM TableX AS t
  JOIN
     Numbers AS n
       ON n.i <= t.repeat ;
like image 64
ypercubeᵀᴹ Avatar answered Sep 18 '22 17:09

ypercubeᵀᴹ