1

I do not speak English, but I always try to learn. Sorry for bad interpretations.

I have a database with 2 tables. This tables are interconnected. See example:

table1

uniqueid,name,type,accountcode
9999999,test,incoming,1

table2

id,name,foo,bar
1, mobile call,foo,bar

In table one, the value accountcode is the same in table two id field. I would like execute a select and show this

table1

uniqueid,name,type,accountcode
9999999,test,incoming,**mobile call**

I'm try INNER JOIN, but the results did not go as expected.

Thanks!!

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
ar.freitas
  • 19
  • 6

1 Answers1

0
  • Join between the two tables using Inner Join with their appropriate relationships.
  • In case of multi-table queries, it is a good practice to use Aliasing, for code disambiguation and readability.

Try the following query:

SELECT 
  t1.uniqueid, 
  t1.name, 
  t1.type, 
  t2.name AS accountcode 
FROM 
  Table1 AS t1 
JOIN Table2 AS t2 ON t2.id = t1.accountcode
Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
  • Hi, thanks for ask my post. I try this query, result is: ` mysql> SELECT -> cdr.calldate, -> cdr.billsec, -> cdr.accountcode, -> ccustos.nome AS accountcode -> FROM -> cdr AS t1 -> JOIN ccustos AS t2 ON t2.id = t1.accountcode; ERROR 1054 (42S22): Unknown column 'cdr.calldate' in 'field list'` – ar.freitas Oct 26 '18 at 14:37
  • @AndersonFreitas once you have aliased the table `cdr` to `t1`, you should now use the alias instead. Use `t1.calldate` and so on.. – Madhur Bhaiya Oct 26 '18 at 14:38
  • 1
    OMG!! Sorry for not perceive this detail. I run again, executing changes and results is exactly what I wanted. Thanks so much! – ar.freitas Oct 26 '18 at 14:42