rearrange two columns into single unique rows - sql

I have a table that has two ID fields:
ID_expired
ID_issued
This table is the only place where this link between IDs is recorded. An ID_issued will show up with a match in these ID_expired column when a new ID_issued occurs (e.g. z234, g123). There are some exact duplicate rows. There are also instances where there is a duplicate ID_issued but no ID_expired listed (e.g. b111).
My objective is to connect all the IDs into a single row so I can refer to the ID history of an individual.

You can create a View and add the table to the view for as many times as there are ID's and join it on itself as many times as well.

Related

Join from multiple tables to one column

I have some problem with sql view. I have some element_ids in my based main table. That column is connected with another 3 tables, there ane unique el_id for that 3 tables. I want to joint that three tables in one column taking another id and write in another column which item it is.
Example:
I take el_id=2 from main table, check if it is in table_1, then I check table_2, there is el_id=2, so I get item_id to my view and write the information in type column in my view.

Power Pivot relationships

Trying to create relationships (joins) between tables in power pivot.
Got 2 tables I wold like to join together, connected with a common column = CustomerID.
One is a Fact Table the other Dim table (look up).
I have run the "remove duplicates" on both tables without any problem.
But I still get an error saying : "the relationship cannot be created because each column contains duplicate values. Select at least one column that contains only unique values".
The Fact Table contains duplicates (as it should?) and the Dim Table do not, why do I get this error?
Help much appreciated
Created an appended table with both columns "CustomerID". After the columns where appended together I could "remove duplicates" and connect the tables together through the newly created appended table.
Don't know if this causes another problem later however.
You can also check for duplicate id values in a column by using the group by feature.
Remove all columns except ID, add a column that consists only of the number 1.
Group by ID, summing the content of the added column and filter out IDs whose total equals 1. What's left are duplicated IDs.

How to deal with one single cell containg multiple values?

I'm having an exercise requiring to create two table for a travel business:
Activity
Booking
it turns out that the column activities in the Booking table references from the Activities table. However it contains multiple value. How do I sort it out? If I insert multiple rows there will possibly duplication in the Booking's primary key.
As Gordon mentioned you should refactor your tables for better normalization. If I interpret your intent correctly this is more like what your schema should look like. Booking should only contain an ID for adventure and an ID for Customer. You will add a row to [AdventureActivity] for each activity booked on a [Booking]. With this design you can JOIN tables and get all the data you require without having to try to parse out multiple values in a column.

How to append new columns with data from one table to another

I know the title might seem confusing but the real situation is as follow: I have two tables with existing data and both of them have n rows but different columns. The order of the rows in two tables do match. So the goal is such that after appending, the first row of the second table is appended to the first row of the first table, etc. and all the columns from the second table are added to the first table - basically just like paste two tables together.

sql: update a given field in all tables instead of just one table

As per another question, sql: update a column if another column poses a conflict in namespace, we know that the following could be used to ensure that a set of 10000 unique package names and 100 categories, having 15000 unique combinations (thus table entries in table categories), could be updated to ensure that the two namespaces don't collide with one another (affecting about 10 entries in total):
UPDATE categories
SET fullpkgpath = fullpkgpath || ',pkg'
WHERE fullpkgpath IN (SELECT value
FROM categories)
However, the fullpkgpath field also repeats in other tables within my sqlite3 database, as per the schema.
Is there a way to have the above UPDATE statement applied to all other tables within a given sqlite3 database with the same fullpkgpath field, without having to manually specify any such extra tables?
If the answer to be above is, "no", then how would I manually specify which other tables I want the statement applied to? Consider that only the categories table has the categories that could be directly compared with names of packages (to be fair, the ports table also has a categories field, but it has all the categories of a given port jammed into one field (space separated), as opposed to separate table entries as is the case in the categories table).