0

I want to make my keyword search in two mysql tables. my tables don't have any identical column names. But I tried few queries, they didn't work for me.

Keyword IS 07731A0328

I tried this:

$sql =  "select a.*, b.* from table1 a inner join table2 b on a.col1=b.htno WHERE a.col1 like '$name'";

$sql =  "select a.*, b.* from table1 a join table2 b on a.col1=b.htno WHERE a.col1 like $name";

Can someone help me with this? Thank you!

TABLE 1

TABLE 1

TABLE2

TABLE 2

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2457175
  • 31
  • 1
  • 7

2 Answers2

1

Join is your friend: http://www.w3schools.com/sql/sql_join.asp

Combine rows from two or more tables, based on a common field between them.

SELECT * FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.col1=TABLE2.htnon 
WHERE TABLE1.col1 = "07731A0328"
Enigma
  • 1,699
  • 10
  • 14
  • got an error. `Database Error: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' ` – user2457175 Jun 14 '13 at 07:10
  • I would guess that the text in col1 and htnon have different formats. See http://stackoverflow.com/questions/9819159/illegal-mix-of-collations-utf8-general-ci-implicit-and-utf8-unicode-ci-implic for the solution to this problem – Enigma Jun 14 '13 at 07:13
0

The query will be

SELECT * FROM Table1,Table2 
WHERE Table1.col1=Table2.htnon AND Table1.col1 = "07731A0328"
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100