Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Searching Multiple tables

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-04-20 : 12:52:17
I am trying to create a custom search functionality in the site, and I need to search multiple unrelated db tables.

how can i get it done with sql?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-20 : 12:56:14
You have to query each table.

SELECT * FROM Table1 WHERE Column1 LIKE 'String1%'
SELECT * FROM Table2 WHERE ColumnA LIKE 'String1%'

If you need better help, please be more specific.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2010-04-20 : 15:19:45
UNION seemed to work fine for now. Thanks!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-20 : 15:21:29
That needs same number and type of retrieved columns in each select - you know!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-20 : 15:58:25
That's why I didn't suggest it since they are unrelated.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-20 : 16:04:38
Yes Tara you're right.

If you need better help, please be more specific.
That's the point.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-20 : 16:41:00
Sorry webfred, I should've quoted who I was replying to. I was replying to xrum's comment.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -