SELECT query question

SELECT query question

am 27.07.2009 21:58:06 von IRytsareva

------_=_NextPart_001_01CA0EF4.912C2F16
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

Hello.

I have 4 tables:

MainTable (Main_ID, Main_Name)
Table1 (Source1_ID, Source1_Name, Main_ID)
Table2 (Source2_ID, Source2_Name, Main_ID)
Table3 (Source3_ID, Source3_Name, Main_ID)

And a search box.

A user can type any names from Source1_Name or Source2_Name or
Source3_Name.
I need to get Main_ID

How to make it?

Thanks, Inna


------_=_NextPart_001_01CA0EF4.912C2F16--

Re: SELECT query question

am 27.07.2009 22:09:20 von joao

select
*
from
MainTable MT
left join Table1 T1 on MT.Main_ID = T1.MainID
left join Table2 T2 on MT.Main_ID = T2.MainID
left join Table3 T3 on MT.Main_ID = T3.MainID
where
T1.Source1_Name = "anything" or
T2.Source2_Name = "anything" or
T3.Source3_Name = "anything"

Not tested.

--
João Cândido de Souza Neto
SIENS SOLUÇÕES EM GESTÃO DE NEGÓCIOS
Fone: (0XX41) 3033-3636 - JS
www.siens.com.br

""Rytsareva, Inna (I)"" escreveu na mensagem
news:3C9BDF0E91897443AD3C8B34CA8BDCA80218F69F@USMDLMDOWX028. dow.com...
Hello.

I have 4 tables:

MainTable (Main_ID, Main_Name)
Table1 (Source1_ID, Source1_Name, Main_ID)
Table2 (Source2_ID, Source2_Name, Main_ID)
Table3 (Source3_ID, Source3_Name, Main_ID)

And a search box.

A user can type any names from Source1_Name or Source2_Name or
Source3_Name.
I need to get Main_ID

How to make it?

Thanks, Inna




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

RE: SELECT query question

am 27.07.2009 22:12:10 von Gavin Towey

Should be more efficient to do something like:

SELECT Main_ID FROM Table1 WHERE Source1_Name =3D 'name'
UNION
SELECT Main_ID FROM Table2 WHERE Source2_Name =3D 'name'
UNION
SELECT Main_ID FROM Table3 WHERE Source3_Name =3D 'name'


-----Original Message-----
From: Jo=E3o C=E2ndido de Souza Neto [mailto:joao@consultorweb.cnt.br]
Sent: Monday, July 27, 2009 1:09 PM
To: mysql@lists.mysql.com
Subject: Re: SELECT query question

select
*
from
MainTable MT
left join Table1 T1 on MT.Main_ID =3D T1.MainID
left join Table2 T2 on MT.Main_ID =3D T2.MainID
left join Table3 T3 on MT.Main_ID =3D T3.MainID
where
T1.Source1_Name =3D "anything" or
T2.Source2_Name =3D "anything" or
T3.Source3_Name =3D "anything"

Not tested.

--
Jo=E3o C=E2ndido de Souza Neto
SIENS SOLUÇÕES EM GEST=C3O DE NEG=D3CIOS
Fone: (0XX41) 3033-3636 - JS
www.siens.com.br

""Rytsareva, Inna (I)"" escreveu na mensagem
news:3C9BDF0E91897443AD3C8B34CA8BDCA80218F69F@USMDLMDOWX028. dow.com...
Hello.

I have 4 tables:

MainTable (Main_ID, Main_Name)
Table1 (Source1_ID, Source1_Name, Main_ID)
Table2 (Source2_ID, Source2_Name, Main_ID)
Table3 (Source3_ID, Source3_Name, Main_ID)

And a search box.

A user can type any names from Source1_Name or Source2_Name or
Source3_Name.
I need to get Main_ID

How to make it?

Thanks, Inna




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgtowey@ffn.com


The information contained in this transmission may contain privileged and c=
onfidential information. It is intended only for the use of the person(s) n=
amed above. If you are not the intended recipient, you are hereby notified =
that any review, dissemination, distribution or duplication of this communi=
cation is strictly prohibited. If you are not the intended recipient, pleas=
e contact the sender by reply email and destroy all copies of the original =
message.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg

Re: SELECT query question

am 27.07.2009 22:20:03 von joao

There are many ways to get the same result. hehehehe

"Gavin Towey" escreveu na mensagem
news:30B3DF511CEC5C4DAE4D0D290504753413956DC089@AAA.pmgi.loc al...
Should be more efficient to do something like:

SELECT Main_ID FROM Table1 WHERE Source1_Name = 'name'
UNION
SELECT Main_ID FROM Table2 WHERE Source2_Name = 'name'
UNION
SELECT Main_ID FROM Table3 WHERE Source3_Name = 'name'


-----Original Message-----
From: João Cândido de Souza Neto [mailto:joao@consultorweb.cnt.br]
Sent: Monday, July 27, 2009 1:09 PM
To: mysql@lists.mysql.com
Subject: Re: SELECT query question

select
*
from
MainTable MT
left join Table1 T1 on MT.Main_ID = T1.MainID
left join Table2 T2 on MT.Main_ID = T2.MainID
left join Table3 T3 on MT.Main_ID = T3.MainID
where
T1.Source1_Name = "anything" or
T2.Source2_Name = "anything" or
T3.Source3_Name = "anything"

Not tested.

""Rytsareva, Inna (I)"" escreveu na mensagem
news:3C9BDF0E91897443AD3C8B34CA8BDCA80218F69F@USMDLMDOWX028. dow.com...
Hello.

I have 4 tables:

MainTable (Main_ID, Main_Name)
Table1 (Source1_ID, Source1_Name, Main_ID)
Table2 (Source2_ID, Source2_Name, Main_ID)
Table3 (Source3_ID, Source3_Name, Main_ID)

And a search box.

A user can type any names from Source1_Name or Source2_Name or
Source3_Name.
I need to get Main_ID

How to make it?

Thanks, Inna




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gtowey@ffn.com


The information contained in this transmission may contain privileged and
confidential information. It is intended only for the use of the person(s)
named above. If you are not the intended recipient, you are hereby notified
that any review, dissemination, distribution or duplication of this
communication is strictly prohibited. If you are not the intended recipient,
please contact the sender by reply email and destroy all copies of the
original message.



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org