First off, I am not an SQL coder.
I am trying to select information from 2 different tables in the same database.
Table 1 is called trans and has 3 columns:
CustNumb, DoT, Amount
Table 2 is called cust and has multiple columns:
CustNumb, Name, Address, City, State, Zip, Phone
The SELECT statement that I’m trying to write will pull data from both tables.
SELECT trans.CustNumb , cust.Name , cust.City , cust.State , trans.DoT , trans.Amount , cust.Phone , FROM trans , cust WHERE CustNumb LIKE 1234
I THINK I need to use a JOIN statement, but I’m sure what kind of a JOIN or the proper syntax.
Thanks for your help!
Advertisement
Answer
You do need a JOIN
. In fact, you should simply never write ,
in the FROM
clause.
The JOIN
you need would appear to be on the common column between the two tables:
SELECT t.CustNumb, c.Name, c.City, c.State, t.DoT, t.Amount, c.Phone FROM trans t JOIN cust c ON t.CustNumb = c.CustNumb WHERE c.CustNumb = 1234;
In addition, you should understand that LIKE
is a string function and 1234
is not a string. Presumably, you just want equality — so use =
.