0

I found this query that can combine two tables with different number of rows and without any related fields:

SELECT a.*, b.* FROM table1 a, table2 b;

Now my problem is that in my case I cannot change the value of the FROM.

Example I have this Query:

SELECT * FROM table1;

I cannot change that to:

SELECT * FROM table2;

At most, I can only add statements after FROM table_name LEFT JOIN somedefaulttable ON somedefaulttable2.id = somedefaulttable .id_c. (I forgot to add this important detail, I can only add custom queries after this line, I cannot remove this predetermined LEFT JOIN as this is system generated) The reason for this is because I am restricted by the CRM I am using, and I cannot edit the default select value but I can add additional custom queries after the said statement.

Now what my main problem here is that I need to combine a different table in my Query and I cannot use join as they don't have any common values and their number of rows are also different, I also tried using JOIN before to no avail, and thus decided to try using a different approach such as merging the two tables.

This is the link to my previous question where I was using JOIN to achieve my goal of combining the tables. In this link, you can see that I want to combine Table A and Table 4 but I cannot do so with JOIN as they have a different number of rows and that I am limited in changing my current Query to fit the posted answer.

Table A.

id | name | deleted | amount | due_date   | status
1  | a    | 0       | 10     | 2016-07-18 | Unpaid
2  | b    | 0       | 20     | 2016-07-19 | Unpaid
3  | c    | 0       | 15     | 2016-07-18 | Unpaid

Table B

id | name   | due_date   | status
1  | a      |            | Unpaid
2  | b      |            | Unpaid
3  | c      |            | Unpaid
4  | d      | 2016-07-19 | Unpaid

Table C

id | table_d_id | table_a_id
1  | 1          | 1
2  | 2          | 2
3  | 3          | 3

Table D

id | 
1
2
3
5
  • @Jens sorry about that, remove the tag. It is MySQL Commented Jul 21, 2016 at 5:42
  • hey why don't you try join? Commented Jul 21, 2016 at 5:46
  • @vishal I already did as stated in my previous question, but the problem is that my main table has lesser rows than the table I want to join, and also, I want to retrieve everything at table 4 with some conditions Commented Jul 21, 2016 at 5:51
  • can you update your questions with the tables Commented Jul 21, 2016 at 5:53
  • @vishal updated with table Commented Jul 21, 2016 at 6:13

2 Answers 2

1

Try this for (inner) joining two tables without a JOIN Statement.

SELECT a.x, a.y, b.x, b.y FROM  table1 a, table2 b WHERE a.x = b.x

What I do not understand is, how different numbers of rows affect the requested solution.

Sign up to request clarification or add additional context in comments.

Comments

0

i have created a link of one to many between the tables with your example and number of rows you inserted you should try this:

     SELECT TableC.*
     FROM TableB, TableD INNER JOIN (TableA INNER JOIN TableC ON TableA.ID =       TableC.table_a_id) ON TableD.ID = TableC.table_d_id;

this will bring all the records of table C

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.