This is my 2 tables.

account_details (account_number, nic, full_name, phone_number, address, gender, date_of_birth,__)

account (account_number, name_with_initials,account_type, fd_period,__)

I want to select records in both the tables. This is my SQL line.

$query ="SELECT account_details. nic,full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period". "FROM account_details,account". "WHERE account_details.account_number=account.account_number";

The following error occurs.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.account_number=account.account_number' at line 1

Recommended Answers

All 5 Replies

May be

$query ="SELECT account_details. nic,full_name,phone_number,address,gender,date_of_birth,account.name_with_initials,account_type,fd_period"." FROM account_details,account"." WHERE account_details.account_number=account.account_number";
select *from account_details ad,account ac
where ad.account_number=ac.account_number
$query ="SELECT ad.nic,ad.full_name,ad.phone_number,ad.address,ad.gender,ad.date_of_birth,a.name_with_initials,a.account_type,a.fd_period FROM account_details ad,account a WHERE ad.account_number=a.account_number";

In this code i have made alias of table account_details as "ad" and for account as "a".
And your error was that you have to write the name of fields along with table from which they are coming.

@ IIM; I tried your query in my coding. But it retrieves all the records irrespective of the account number. I want to display ONLY the relevant record set?

You will need two different connections for two different tables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.