Explanation of SQL code - sql

Can anyone explain to me what the following code does? Thanks.

1) this code joins Subscribers table records with Relatiws table records where Subscribers table phone number is equals to Relatives table column 'subscriber' value.
2)Then this code joins resulting table records from first step with Activities table records where Relatives table column 'FamilyMember' value is equal to Activities table column 'Subscriber' value.
Resulting table from step two has 10 columns
1 PhoneNumber
2 Name
3 SubscriptionDate
4 Subscriber
5 FamilyMember
6 ID
7 Subscriber
8 Date
9 Type
10 Content
3)then this code selects column 'Contents' values from resulting table from second step where name is 'Ringo Star' and type is 'Message received'.

Related

Selecting multiple values from another table on SQL (phpMyAdmin)

I've been trying to select multiple values from another table (i.e. texts in multiple rows) and display it on main table so that multiple values can be on one cell.
(also, I don't speak English, so some terms might sound different, sorry)
Example:
1st table:
ID
Name
Value1
1
Cell 2
A; B
2
Cell 4
B;C;D
2nd table (column Value1 is connected to the previous table's Value1 column):
ID
Value1
1
A
2
B
3
C
4
D
5
E
So in the first table I want to put both values in one cell from the 2nd table
Thank you!
At the moment, I am able to select only one value for Value1 column in the first table that is referenced to the second table.
On phpMyAdmin, I tried to add several columns on one constraint, but error occurred.

Compare column values of different rows - SQL

Currently I have a table with the following columns and data
Id
Revision
Name
Desc
Status
Schema
CreatedBy
First
row
123
xyz
new
1
person1
Second
row
123
abc
modified
1
person2
I am attempting to compare the rows of this table by column values and output the result to a temporary table that shows what data was been changed (from the row above):
Column
Value
Id
Second
Desc
abc
Status
modified
CreatedBy
person2
When data is common between the two rows there is no need to add to the temporary table but when data is modified from the row above the modified values get added to the output table along with their column names.
Any help getting started on the code for this functionality would be greatly appreciated!

Vba sql table join on matching field where 2nd field not matching

Good day everyone. I'm sure this is a fairly common issue but I trawled the internet and I cannot find an answer that works in my case. I have 2 tables which both have 2 fields and both field names are the same. I need to select all records in table 1 where the 1st field matches table 2 1st field and the 2nd field in table 2 does not match field 2 in table 1. Sorry if I'm not explaining this very well. Table 1 has around 10K records with client-name and country. table 2 is a unique list of client names (around 1K) with client-name and country fields. so I need to select all the records from table 1 with same client-name but where country in table 2 is not the same as in table 1. I've been on this for several hours now so any help would be most welcome.
The data is in 1 Access Database and I'm using ADO connection. What I have is:-
SELECT [client-name], [country] FROM [table1] LEFT JOIN [table2] ON [table1].[client-name]
= [table2].[client-name] WHERE NOT [table1].[country] = [table2].[country];

Inner Join query between 2 tables with multiple conditions

We have 2 tables Application and Address, Application table has columns like home_address,office_address and delivery_address and all these 3 column is of number type having values like say 111,112 and 113 for a row of it.It has many such rows. In a separate table we have say column like id and address having lot of records with different id's. we need to get output like say all above 3 columns plus 3 more columns like say full_homeaddress, full_officeaddress , full_deliveryaddress in every row of output.
If it was only one column like home_address in Application table, i would have easily done the join with primary key of Address table and one foreign key of Application table but here we need to display full address of 3 different fields simultaneosly in each row of output.
I think for one row of output, i will have to get records from 1 row of Application table and 3 different rows of Address table to display in every row of output. For these 3 columns of Application table , required addresses are in 3 different rows of Address table.
Kindly help how to write join for it
SELECT app.*,
home.address_description,
office.address_description,
delivery.address_description
FROM application app,
Address home,
Address office,
Address delivery
WHERE
app.homeaddressId = home.addressId(+)
AND app.officeAddressId = office.addressId(+)
AND app.deliveryAddressId = delivery.addressId(+)

Numbers help creating aggregates

I have a table with rows of multiple types. How do I create another table from it so that the rows in this table reflect the sum of all rows of each type from the previous table.
For e.g. I have a Table1 with 5 rows of type A, 6 rows of Type B. I want to create a table (Table2) that contains one row of type A (which is sum of all the 5 rows from Table1) and one row of type B (again this is the sum of all 6 rows from Table1).