-2

I have 2 different tables. I need to get a name from the TMK table in table 1 as below, and I need to bring the total number from my 2nd table. I can't write join. can u help me

TMK Table;

| tmkName | 

| George  |

| Jacob   |

flowNewStatus Table;

|statusId|

| 1 |

| 2 |

if george has number 1 status i want this join

| tmkName |  |statusId|
| George  |    | 1 |
  • 2
    If your tables only have 1 column each, how you are defining the relationship? – Thom A Oct 12 '18 at 10:01
  • @Chanukya and what happens if the statement `INSERT INTO TMK VALUES ('Dave');` is run? Should George's status become 2? (also, comment's aren't the right place for answers) – Thom A Oct 12 '18 at 10:12
  • @Larnu for existing data setup i had given not with new insertions – Chanukya Oct 12 '18 at 10:14
  • @Chanukya my point is that assuming the OP's data will never change is a poor assumption. – Thom A Oct 12 '18 at 10:19
  • @Larnu yeah correct why we need to have unnecessary discussion the person who is asked the question has no response let's close it – Chanukya Oct 12 '18 at 10:21

1 Answers1

0

Before getting to possible SQL queries... from the tables you show you'd need an additional table that associates the person to status, a join table. Essentially a TMK_status table:

TMK_status table

| personID | statusID |
|----------|----------|
|    1     |    1     |
|    2     |    3     |
|    3     |    1     |

Alternatively, the statusID could be stored as a column of TMK thus,

TMK table

| personID | tmkName  | statusID |
|----------|----------|----------|
|    1     |  George  |    1     |
|    2     |  Jacob   |    3     |

If by "I can't write join", you mean you don't know how, check this answer: What is the difference between "INNER JOIN" and "OUTER JOIN"? - you will need an inner join.

If, on on the other hand, you mean you can't use join statements, then you could write a subselect statement. There could be other solutions but they depend on how you decide to join/relate the 2 tables.

  • Please don't answer unclear questions. It makes a mess. Comment asking for edits that clarify. If you don't have the rep then wait. – philipxy Oct 12 '18 at 23:44