开发者

PHP / MySQL - Need help with simple query

I need to write a query but am a new开发者_如何学Pythonbie to writing querys that involve 2 tables.

the first table 'clients' has the following columns "id, archive_reason, name, phone" .. the second table, 'archive' has the following columns "id, archive_reason".

What i need to do is get the archive reason based on the archive_reason in the clients table if that makes sense ... and then return * from the clients table, including the archive reason from the arhive table.

Cheers,


SELECT clients.*, archive.archive_reason FROM clients, archive WHERE clients.id=archive.id;

Is that what you were asking for?

This is called a JOIN, and there are many more (and better) ways to do it:

http://www.w3schools.com/Sql/sql_join.asp

http://www.databasedev.co.uk/query_joins.html


This page should get you started: http://www.w3schools.com/Sql/sql_join_inner.asp.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜