Need Help With SQL Statement

Need Help With SQL Statement

am 04.12.2005 05:53:17 von Michael Avila

------=_NextPart_000_0000_01C5F864.BC6C4F40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I am not much of a SQL guru so I am having trouble trying to figure out how
to format a SQL statement.

I have a table with members named members. Each member has only 1 record.
Then I have a table with member telephone numbers in it name
membertelephones. A member can have more than one telephone number (home,
work, cell, pager, fax, etc.). I want to print out the telephone numbers of
the members. Is it possible to do it in one SQL statement like with a JOIN
or something or do I need to get the members and then loop through the
membertelephones to get the telephone numbers? Is it possible to do a JOIN
with a table with one record with a table with multiple records?

SELECT * FROM member

SELECT * FROM membertelephone WHERE member_id = the id from the above SELECT

Thanks for the help.

Mike





------=_NextPart_000_0000_01C5F864.BC6C4F40
Content-Type: text/plain; charset=us-ascii


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org
------=_NextPart_000_0000_01C5F864.BC6C4F40--

Re: Need Help With SQL Statement

am 04.12.2005 15:10:49 von Marcel Forget

--------------050503010006050301010409
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

*SELECT * FROM member, membertelephone WHERE membertelephone.member_id =
member.id*

That is assuming the unique identifier field is called id in the member
table.

Cheers,

Marcel

Michael Avila wrote:

>I am not much of a SQL guru so I am having trouble trying to figure out how
>to format a SQL statement.
>
>I have a table with members named members. Each member has only 1 record.
>Then I have a table with member telephone numbers in it name
>membertelephones. A member can have more than one telephone number (home,
>work, cell, pager, fax, etc.). I want to print out the telephone numbers of
>the members. Is it possible to do it in one SQL statement like with a JOIN
>or something or do I need to get the members and then loop through the
>membertelephones to get the telephone numbers? Is it possible to do a JOIN
>with a table with one record with a table with multiple records?
>
>SELECT * FROM member
>
>SELECT * FROM membertelephone WHERE member_id = the id from the above SELECT
>
>Thanks for the help.
>
>Mike
>
>
>
>
>
>
>----------------------------------------------------------- -------------
>
>
>
>

--------------050503010006050301010409--

Re: Need Help With SQL Statement

am 04.12.2005 15:10:49 von Dijital

Yes you can do a join but you must have a unique identifier (such as an
id number) in both tables with which to match off of. If you had a
member table defined with the columns member_id and member_name, and the
membertelephones table with member_id and member_phone, and in these
tables your member_id is the common reference, then to get the id, name
and all the phone numbers for only the specified member id, your query
would look something like this:

select member.member_id,member.member_name,membertelephones.member_ phone
from member inner join membertelephones on
member.member_id=membertelephones.member_id where
members.member_id=""

This would output x number of records, each with the id, name and phone
number for the member identified by . Note that here,
you are not using the select * method, which should be avoided any ways,
as it is wasteful because it selects ALL column data, rather than just
the columns whose data you want to retrieve. Cheers.

Armando

Michael Avila wrote:
> I am not much of a SQL guru so I am having trouble trying to figure out how
> to format a SQL statement.
>
> I have a table with members named members. Each member has only 1 record.
> Then I have a table with member telephone numbers in it name
> membertelephones. A member can have more than one telephone number (home,
> work, cell, pager, fax, etc.). I want to print out the telephone numbers of
> the members. Is it possible to do it in one SQL statement like with a JOIN
> or something or do I need to get the members and then loop through the
> membertelephones to get the telephone numbers? Is it possible to do a JOIN
> with a table with one record with a table with multiple records?
>
> SELECT * FROM member
>
> SELECT * FROM membertelephone WHERE member_id = the id from the above SELECT
>
> Thanks for the help.
>
> Mike
>
>
>
>
>
>
> ------------------------------------------------------------ ------------
>
>

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: Need Help With SQL Statement

am 04.12.2005 15:12:53 von Marcel Forget

--------------050908010105000408050601
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Sorry but the mail list changed my formatting from bold and replaced it
with extra *.

Its should read:

SELECT * FROM member, membertelephone WHERE membertelephone.member_id =
member.id


Marcel Forget wrote:

>*SELECT * FROM member, membertelephone WHERE membertelephone.member_id =
>member.id*
>
>That is assuming the unique identifier field is called id in the member
>table.
>
>Cheers,
>
>Marcel
>
>Michael Avila wrote:
>
>
>
>>I am not much of a SQL guru so I am having trouble trying to figure out how
>>to format a SQL statement.
>>
>>I have a table with members named members. Each member has only 1 record.
>>Then I have a table with member telephone numbers in it name
>>membertelephones. A member can have more than one telephone number (home,
>>work, cell, pager, fax, etc.). I want to print out the telephone numbers of
>>the members. Is it possible to do it in one SQL statement like with a JOIN
>>or something or do I need to get the members and then loop through the
>>membertelephones to get the telephone numbers? Is it possible to do a JOIN
>>with a table with one record with a table with multiple records?
>>
>>SELECT * FROM member
>>
>>SELECT * FROM membertelephone WHERE member_id = the id from the above SELECT
>>
>>Thanks for the help.
>>
>>Mike
>>
>>
>>
>>
>>
>>
>>---------------------------------------------------------- --------------
>>
>>
>>
>>
>>
>>
>
>
>

--------------050908010105000408050601--