How to remove mirrored datasets from MS Access DB? - sql

I am experiencing a problem with mirrored datasets. This situation occured because the data model was switched a few months past and I just got recently assigned to this project, which already had a new application and data model done.
I was tasked with importing all the data from the old MS Access application to the new one and here's where the error has its source. The old data model was written in a way that every dataset was also stored as its mirrored counterpart. Imagine a database table like this:
pk | A | B
1 | hello | world
2 | world | hello
I imported the data via a self made staging process via Excel and VBA coding and that worked fine. The staging was necessary because I wanted to create insert statements and therefore had to map all the old IDs, names, ... to the news ones.
While testing the application after the import was done, I realized that the GUI showed all datasets twice. (The reason for it being shown twice and not once and then once again in mirrored form, is the way we fill the ListBox that shows the results)
I found the reason for that error in the mirrored data and now would like to get rid of it. The first idea I had is rather long and probably over-complicated, that's why I am posting here, in hope of finding a shorter solution.
So, my idea is as follows and would use solely VBA coding:
Filling recordSet with a SELECT * FROM mirroredDataTable
Write a SQL-Statement and check if the recordCount of that statements result is >1 for each record in the recordSet from 1.)
If the resultCount is >1 then one of the IDs in that result is written into a new recordSet or Array
The recordSet / array from 4.) is parsed again and for each ID in there I create a DELETE statement
???
profit
Now I already have an idea for the SQL statement in 2.), but before I begin I'd just like to ensure that there is no "easy" way that I haven't considered yet or just have overlooked.
Would greatly appreciate any help/info/tips you can provide.
PS: It is NOT an option to redesign the whole data model or something among the lines of this (not my decision)

Thanks to #Gord Thompson I was able to solve this issue on a purely SQL basis. See the answer of this subthread for the detailed solution: How to INTERSECT in MS Access?

Related

Using MS Access to obtain data across linked tables

I'm new to MS Access and am trying to speed up a data gathering process that is taking forever in Powershell. In Powershell I have 10 or so web API calls to get data and each comes back as an object with multiple properties (fields.) Each set of data has related fields to 1 or more of the other sets of data. Getting the data is very quick but piping an array of objects to where-object to select-object takes over an hour and there's really not that much data. Each object contains 500-1500 "records" and 5 to 10 "fields" so I thought why not export that data and use something that's intended to search through data to do the job? I exported each object as a separate .CSV file. So enter MS Access..
I imported each of the CSV's as a separate table (easy enough.) I'm going to simplify this down for this example to the following 3 tables:
[Tables]https://i.stack.imgur.com/UCH1F.jpg
Every table has fields that relate it over to other tables. Pretty much there's some sort of Id field in every table that is related to another Id field in a different table that I need to pull a field called "name" from. I'm trying to follow the bread crumbs from the Player name to it's Network name to it's Application name, to it's Layout name, etc... I want to build a query that I would eventually just be able to export as an Excel file. I also would prefer to just write out the SQL unless it's really easier to to understand the visual query builder. I'm looking to build a sheet with the following information:
Player's Name would include all names from the Players table and getting just that data makes sense to me. SELECT Name AS PlayerName FROM Players Everything else, not so much. I feel like this will end up being some mega query as I get deeper into related table after related table. In Excel, it would be straightforward using Vlookups across tabs but that doesn't seem to be the best approach. Given the info above, I'm trying to achieve the following output:
Result table
Any help with strategy and syntax greatly appreciated!
You're looking for the JOIN clause.
SELECT
Players.Name PlayerName, Networks.Name PlayerNetwork, Applications.Name ApplicationName
FROM
Players
LEFT OUTER JOIN
Networks
ON
Networks.ID = Players.NetworkId
LEFT OUTER JOIN
Applications
ON
Applications.Id = Players.ApplicationID

TDBGrid where is the SQL WHERE condition?

I am working on an already started Delphi project where there is a TDBGrid. The grid seems to be filled by a TADOTable that refer to a Bill table in the dataset.
It display a bill by PkBill. I can't seem to find where in the design or in code someone told to load only for this pk.
I need to load multiples Pk at the same time. I'm used to create programmatically a TADOQuery, create a connection, write my SQL code, then do what I want with the result. With those objects/controls, I just don't know where to do that.
Thanks for the help and clarity!
Check TADOTable.MasterSource to see if it's in the Master-Detail relationship.
Or you could check TADOTable.Filtered and TADOTable.Filter to see if it's being filtered by PkBill.

exporting only rows from sql in phpmyadmin, only where a certain column has Boolean of 0

"meta/background about the use of code and person using it"
1.site built by professional that left company,
2.I am inexperienced but trying/ want to learn,
3.Customer support site for service reps,
................................................
What im trying to do exactly per stackoverflows parameters.
We have a drop down box listing issues that the customer had in a column labeled "issue_type". I can export via csv entire table load onto excel then give to boss for overall review of what the issues were. However data base has a "hide" column. Its function is that when the row is updated the record is kept but the same "job or call" has only one viewable report on site (the most recently updated one). Hide is a boolean. In conclusion I want to export rows that only has the "hide" column Boolean status at 0, AND to only export the columns "customer", and "issue_type". I can seem to only do one or the other. and have researched a minimum of 4 hours to find answer myself and cannot find a syntax to do both at the same time with phpmyadmin.
I dont want an enormous data that is mostly useless but for issue type and customer but i will have to manually delete all the rows with hide = 1?
Thanks anyone 1st attempt question sorry if not correct for stackflow.
SELECT Customer,Issue_type FROM tickets where hide =0;
Elaborating on what is above for anyone that may be looking for a similar answer, SQL supports the "where" clause of which you can when properly syntaxed select many of your columns and their associated strings, booleans, and numbers to = what your looking for. Wildcards I found later for other uses work as well.
Sorry about the self answer but hopefully someone finds this usefull

Copy one database table's contents into another on same database

I'm a bit of a newbie with the workings of phpmyadmin. I have a database and now there are 2 parts within it - the original tables jos_ and the same again but with a different prefix, say let's ****_ that will be the finished database.
This has come about because I am upgrading my Joomla 1.5 site to 2.5. I used a migration tool for the bulk of the new database but one particular piece of information did not transfer because the new database has a different structure.
I want to copy the entire contents of jos_content, attribs, keyref= across to ****_content, metadata, "xreference"."VALUE" if that makes sense. This will save manually typing in the information contained within 1000s of articles.
jos_content, attribs currently contains
show_title=
link_titles=
show_intro=
show_section=
link_section=
show_category=
link_category=
show_vote=
show_author=
show_create_date=
show_modify_date=
show_pdf_icon=
show_print_icon=
show_email_icon=
language=
keyref=41.126815,0.732623
readmore=
****_content, metadata currently contains
{"robots":"all","author":""}
but I want it to end up like this
{"robots":"","author":"","rights":"","xreference":"41.126815,0.732623","marker":""}
Could anyone tell me the SQL string that I would need to run to achieve this please?
If it makes any difference I have manually changed about 300 of these articles already and thought there must be a better way.
Edit: Being nervous of trying this I would like to try and find the exact syntax (if that's the right word) for the SQL Query to run.
The value I want to extract from the source table is just, and only, the numbers next to keyref= and I want them to turn up in the destination table prefixed by "xreference". - so it shows "xreference"."VALUE" with VALUE being the required numbers. There is also an entry - ,"marker":"" that is in the destination table so I guess the Query needs to produce that as well?
Sorry for labouring this but if I get it wrong, maybe by guessing what to put, I don't really have the knowledge to put it all right again....
Thanks.
Please Try it
insert into tableone(column1,column2) select column1,column2 from Tablesecond
if You have not Table another Daabase Then This query
select * into anyname_Table from tablesource

MS Access/VBA Same code same data different results

This one has got me stumped but good. Using VBA in MS Access, I sometimes get different results when running the same code against the same table. I can run the code 2, 5, 6, 10 times and get the same results, then run it again and get a different result. I can run the code twice and get the same results and then I can run the code twice and get different results - all with the same code against the same table.
The code is used to group trips so they can be billed correctly. I do this by taking the raw SQL data and putting it into an Access table, then via several sorts and some cross-checking, I label each trip in the access table with a GR or an ML in the last field of the table. The result set is all trips for the specified time frame which are now labeled: ML (multi-loaded), GR (Grouped) or blank (demand).
I have even tried putting in MoveLast/MoveFirst to make sure the table is fully loaded each time (per suggestion from others).
Here is a link to the code and data after 2 runs of the same code on the same data:
Code&DataI removed the trip ID and client ID data for privacy concerns. The trip ID is unique but the client id will be used many times depending on how many trips the client took during the time period.Any and all help you can give to make this code produce the same results each time it is run is GREATLY appreciated. I don't want to have to go back to doing this report labeling by hand. This is the smallest of 4 that must be done twice a month.Thanks!David R. Mohr.................................................end of line........................................................................
When opening t_BillableTrips, I do not think it is safe to assume that the data will be sorted the way you want. That could potentially change from run to run. I would suggest to use a query with an explicit sort order instead of opening the table directly. My second suggestion is to use the Recordset Clone method to get Intable2 and Intable3. The recordsets will be sharing the same underlying in memory data but will be able to be positioned at different records.
First of all, Thanks to everyone that gave an answer. Your prompts guided me to find the solution.
1st problem is that I was directly editing the TABLE while being under the impression that my MAKE TABLE ORDER BY command was actually creating a table in the order I specified - it only worked most of the time and we can't have that.
So, after digging deeper I found more and more evidence that trying to sort the actual table - especially with a MAKE TABLE command is not good practice and can give unpredictable results as well as generates a lot more overhead. I am now basing my positioning and updating on a QUERY of the table and not the actual table. I.E. changed this:
Set InTable = dbsBilling.OpenRecordset("t_BillableTrips", dbOpenTable)
Set InTable2 = dbsBilling.OpenRecordset("t_BillableTrips", dbOpenTable)
Set InTable3 = dbsBilling.OpenRecordset("t_BillableTrips", dbOpenTable)
Set InTable4 = dbsBilling.OpenRecordset("t_BillableTrips", dbOpenTable)
to this:
Set InTable = dbsBilling.OpenRecordset("q_BillableTripsSort1B", dbOpenDynaset)
Set InTable2 = dbsBilling.OpenRecordset("q_BillableTripsSort1B", dbOpenDynaset)
Set InTable3 = dbsBilling.OpenRecordset("q_BillableTripsSort1B", dbOpenDynaset)
Set InTable4 = dbsBilling.OpenRecordset("q_BillableTripsSort1B", dbOpenDynaset)
So far, this seems to have fixed the problem and, of course, the proc runs much faster since it does not have to create the table twice to run/update for two different sorts.