Retrive unique records from an access table which does not have a fixed structure - vba

I want only the unique records in same or new table. And I want to do this with different tables (having duplicate records) in access database through same code.
The flow should be like:
input table ------VBA MODULE------> table with unique records
I am able to do this group by function but for that i have to use field names in query. But field names will differ from table to table.
Please help!

Just use query
SELECT DISTINCT * FROM MyAnyTable

Related

MS Access - create JOIN table to store value for every combination

I am working on an MS Access 2013 database. I have two tables:
Customers (28 records)
Chemicals (34 records)
I need to create a table for usage rates for each customer for each chemical.
The rates will be entered manually (at user's request). I am trying to determine how to create a new table where the customer-chemical fields will combine to be primary key.
The resulting table should have 28x34=952 unique records.
The goal is to then have a form wherein the user can select the customer, then the chemical, and edit the rate.
For any table/query creation I am comfortable using either the Access interface or SQL.
I will advise to create a new table containing 4 columns. The first column will be an 'id' it is going to be your primary key (auto-increment if you want), second column is the customer, then the chemical, and finally the rating. Then if you format your query to select 'rating' where customer='customer name' and chemical='chemical name', you should get the desired result you want.
Thank you for the reply. Did a little more wrestling with it and used the following SQL to create the table:
SELECT customers.customer, chemicals.chemical
INTO UsageRates
FROM Chemicals, Customers
Then adding a blank 'rate' field to the table.

Merge or Union tables in Access

I have two tables that I would like to combine into an unduplicated list. I have a 'SUB' table that has a 1 column named 'ID' containing a unique identifier for 11,000 some records. I also have another table with 75,000 rows called 'MASTER'. It contains two columns, 'ID' which has the same unique identifier and 'CODE' which contains a unique code for each ID. I want to create a new table that has the 11,000 IDs from the 'SUB' table with the corresponding 'CODE's that match the 'SUB' IDs from the 'MASTER' table. I have used a basic UNION Query, but the results had duplication in the 'ID' column. I tried to consolidate the table produced by that query using Excel, but the list was too long to crunch. Any help? I know this is a basic, but I am not a database person... What would the SQL code look like to achieve this?
Thanks!
You should use JOIN instead of UNION to achieve what you want.
Something like that should work:
SELECT SUB.ID, MASTER.CODE
FROM SUB
JOIN MASTER
ON SUB.ID = MASTER.ID
In general, JOIN allows you to match some rows from one table to the rows from other table according to the value(s) in these rows (think of it as "gluing" rows together along the vertical axis to form longer rows), while what UNION does is just adding all rows from one table below other table (i.e. appends one table to the end of other table along the horizontal axis).

sql - using result of query as input to another query

I got a DB with many tables, and I'm able to make a query that results in each record being the tables' names.
I created an example here:
http://sqlfiddle.com/#!4/fa87b/3
Where what I need is another query that uses the existent one 'iterating' the name in result table.
What I want now is to query all the tables for one specific column.
Like for example:
SELECT column1 FROM (all tables which names are in a query result).

Get fields from one column to another in Access

Below i have a table where i need to get fields from one column to three columns.
This is how i would like the data to end up
Column1
Music
Column2
com.sec.android.app.music
Column3
com.sec.android.app.music.MusicActionTabActivity
Give the table a numeric autonumber id
Remove the rows with no data with a select where blank spaces or null
Find records with no point in the content with a select
Use the previous query as a source and use the id to find the id + 1 to find the next record and do the same with + 2 to find the second row
Build a table to hold the new structure and use the query as a source to insert the new created data in the new table with the 3 columns structure.
This is an example using sql server
Test table design
Data in table
Query
Look at the query from the inside. The first query inside clean the null records. Then the second query find the records with out point. This records are the reference to find the related two records. Then the id of the records with out point are used to make a query in the select adding 1 for the next record and then other query adding 2 to find the other record. Now you only need to create a table to insert this data, using this query as the source.

Using Excel range of cell values for ms query single paramter

I have an excel sheet with two fields: list of user id, and corresponding create date. I want to query from an external database having around million records by only returning records where user_id in (?). How can i pass a range of id's like $A1:A17 as the single parameter to the query?
One option to achieve the same result using another method would be to create a temporary table with just one column for user_id.
Then you could run the query and do:
where user_id in (select user_id from my_temp_table)