Getting data from joined tables Ruby - mysql

In summary, I need to grab columns from three tables, which all are associated with each other through inbetween tables.
There are four cases with the data:
1. Has data in table A, has data in table B, has data in table C
2. Has data in table A, has data in table B, does not have data in table C
3. Has data in table A, does not have data in table B, has data in table C
4. Has data in table A, does not have in table B, does not have in table C
Is there a single active record query I can use to get the data for all these cases? I cannot use join because the query dies if it come across a row missing any of the pieces. I have tried .includes and .eager_load, but then it does not include the columns from table B or C.
Thank you for your help.

Related

Alternating Tables

I have three tables and each table has its own dataset:
Table A - Dataset A
Table B - Dataset B
Table C - Dataset C
When running the report I get this:
Table A
Table A
Table A
...
Table B
Table B
Table B
...
Table C
Table C
Table C
...
First all the Data of table A is displayed, then table B, then table C. What I want to achieve is that the tables are alternating. It should look like this:
Table A
Table B
Table C
Table A
Table B
Table C
...
Unfortunatly it is not possible to join these three tables via SQL and I want to avoid to use the lookupset-expression, because then all the data would be displayed in one single cell and not in rows and that looks badly. Or is there a way to generate an new row via expression, similar to Environment.NewLine?
I think the best would be to use subreports for the other 2 tables. I assume there some sort of way to associate the planets to the moons that would be used for the parameters. Then add extra add extra Row in Group for the Moon subreport.
The solution proposed by Hannover First works fine. Working with Sub-Reports solves my problem.
Thanks.

How to get the first 4 rows of each record in table and append to the select instead rather than rows?

I have two tables:
documents table
audits table.
audits table is a polymorphic table and has auditable_type and auditable_id which is linked to the id of documents table. audits table also has event and new_values column.
Here's the table schema.
documents table has user_defined_field JSON column.
My goal is I want to get the first 4 values of the status field in user_defined_field JSON column. There will be a column in the report of the web app to display the 1st Status, 2nd Status, 3rd Status, 4th Status.
So basically, it's like the documents table is join to audits table and should get the first 4 record of the document id and display it in the SQL select as status_1, status_2, status_3, and status_4
Thank you.

Refresh MySQL table after updation

I have three tables A, B, C. I have a entity D which is a resultant of these three tables obtained using inner joins on various attributes. Now, I got a row updated in table A and a new row got added in table B. How can this be managed, so that my table D gets updated automatically? Each of these tables consists of 100 000 records.

I want to concatenate two tables. Table A(a, b, c), Table B(d) should become Table A (a,b,c, d)

I want to append a table with another table. Table A(a, b, c), Table B(d) should become Table A(a,b,c, d). Assume both tables have same number of records.
I do not think there is any way to do this. Also, this is not logical. What you can do is do a join between the tables. A join is necessarily a Cross product between table A and table B. Read more about joins.

How to import table into an existing table

I have two tables with identical structures. Let's call them table A and B.
Table A consists of records with ID as primary key from 1-10 and B has the table with IDs 11-20.
Given I have imported table A into mysql table, how can I, in a way, concatenate table B to A?
Any thoughts will be much appreciated :D
You use insert:
insert into tablea
select *
from tableb;
It is better to list the columns for the insert and select, but you can do it with this syntax if the tables really do have identical formats.