0

I have two tables

Table 1 and table 2

I would like to get all the data from Table1 and one column's value from table 2.

Unique details for both tables are the mobile number.

So I tried this:

SELECT d.*, a.paymentmode FROM table1 d JOIN table2 a ON d.user = a.mobile WHERE a.mobile = '+911234567890'

I get double results.

Like: For the above mobile number.

Order1

Order1

Order2

Order2

Order3

Order3

Order4

Order4

enter image description here

What is the issue here? How do I show only Order1, Order2, Order3, Order4 instead of double?

Sanjana Nair
  • 2,663
  • 6
  • 26
  • 44

2 Answers2

0

Assuming Table 1 user column is a mobile number, what you're missing is the type of JOIN

Types of join and their logic can be found here

Btw - Another thing I would do is remove all none numeric keys ('+', '-' etc) from the mobile number fields, it can save possible JOI errors etc.

Guy Louzon
  • 1,175
  • 9
  • 19
-1

I think you need to use Group by.

 SELECT t1.*, t2.column_name FROM table1 AS t1 JOIN table2 AS t2 ON t1.mobile = t2.mobile WHERE t2.mobile = '+911234567890' GROUP BY t1.mobile
Nashir
  • 254
  • 1
  • 5
  • 9