Chris
Chris

Reputation: 1129

How to get the archive reason based on the archive_reason

I need to write a query but am a newbie 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.

Upvotes: 0

Views: 55

Answers (1)

Brad
Brad

Reputation: 163468

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

Upvotes: 1

Related Questions