-1

I have two table:

  1. Table 'temp_hsl'
|id|kota_a|  
|41| 1    |
|42| 2    |

  1. Table 'jarak kota'
|id|kota_a|kota_b | jarak|
|1 |1     |1      | 0    |
|2 |1     |2      | 2    |
|3 |1     |3      | 3    |
|4 |2     |1      | 2    |
|5 |2     |2      | 0    |
|6 |2     |3      | 3    |
|7 |3     |1      | 3    |
|8 |3     |2      | 3    |
|9 |3     |3      | 0    |

I want end result:

|id|kota_a|kota_b | jarak|
|1 |1     |1      | 0    |
|2 |1     |2      | 2    |
|3 |2     |1      | 2    |
|4 |2     |2      | 0    |

The result above is based on a relation table with table temp_hsl. How do it with command mysql? I 've tried , but the results of its query looping continues.

STT LCU
  • 4,348
  • 4
  • 29
  • 47
user4716022
  • 15
  • 1
  • 5
  • 1
    Read up on JOINS http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins – Funk Forty Niner Apr 01 '15 at 03:37
  • This question is about extremely basic programming concepts, and thus it is showing low effort from the asker. Also, it has nothing to do with PHP. – STT LCU Apr 01 '15 at 13:01
  • Oh and moreover, it's a duplicated, that can also be answered by google. this is an example of which questions ARE NOT WELCOME in stackoverflow. – STT LCU Apr 01 '15 at 13:02
  • for all : I'm sorry... And @STT LCU : I'm sorry too – user4716022 Apr 01 '15 at 13:13

3 Answers3

0

Not exactly sure what you are asking, but you should be able to do something like: select * from tableX where fieldX in (select fieldX from tableY)

slackwars
  • 504
  • 5
  • 18
0

If I am not wrong you can alias your table first and use the below SQL Query. it may help you to solved your query

SELECT A.id, A.j FROM jarak_kota A INNER JOIN temp_hsl B ON A.kota_a = B.kota_a LIMIT 0 , 30

Mukesh S
  • 367
  • 5
  • 19
  • You have to add where condition like kota_b IN (1,2) Use this SELECT A.id, A.kota_a, A.kota_b, A.jarak FROM jarak A INNER JOIN temp_hsl B ON A.kota_a = B.kota_a WHERE A.kota_b IN ( 1, 2 ) LIMIT 0 , 30 .... You can find the same records which you want – Mukesh S Apr 01 '15 at 10:36
  • I've tried this code: SELECT A.id, A.kota_a, A.kota_b, A.jarak FROM jarak A INNER JOIN temp_hsl B ON A.kota_a = B.kota_a WHERE A.kota_a IN ( 1, 2 ) LIMIT 0 , 30. but this is not the expected results. Do you any solution? :) – user4716022 Apr 01 '15 at 12:45
  • @Ashmik please do not help further this user. This question is lowering the quality of the site. Just let it be, it's going to be closed. thank you. – STT LCU Apr 01 '15 at 13:05
0

Use this, just edit @Ashmik's answer should work fine if you don't edit your question again.

SELECT A.id, A.kota_a, A.kota_b, A.jarak FROM jarak_kota A INNER JOIN temp_hsl B ON A.kota_a = B.kota_a LIMIT 0 , 30

Jash Parekh
  • 1,097
  • 2
  • 10
  • 15