Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 13th, 2004, 01:38 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Record Exists

Hello Everyone and thanks for your help in advance. I am writing an application that needs to search various tables by an ID column to determine if a match exists in any of the tables, and preferably a count of matches. However, SQL is not my strong suit. Can anyone give me some help getting this rolling? Any feedback is greatly appreciated. Thanks.

Reply With Quote
  #2 (permalink)  
Old September 13th, 2004, 02:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

select count(ID) from Table where field like '%whataever text%'

Something like that...

Brian
Reply With Quote
  #3 (permalink)  
Old September 13th, 2004, 02:20 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sort of except that I need to check multiple tables i.e.

Select Count(*)

Table1, Table2, Table3

Where ID=1

Reply With Quote
  #4 (permalink)  
Old September 13th, 2004, 02:36 PM
Authorized User
 
Join Date: Apr 2004
Location: Boise, ID, USA.
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you want to know where the match is found, or merely that the match is found?

Code:
SELECT COUNT(*), source
  FROM (SELECT ID, 'table1' source 
          FROM table1
         WHERE ID = 1
        UNION ALL
        SELECT ID, 'table2' source 
          FROM table2
         WHERE ID = 1
        UNION ALL
        SELECT ID, 'table3' source 
          FROM table3
         WHERE ID = 1)
 GROUP BY source
will give you a count of matches by table.


Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
list.exists Maxxim ASP.NET 2.0 Professional 13 September 4th, 2007 06:51 AM
"A command with that name already exists" Aaron Edwards Visual Studio 2005 2 March 9th, 2007 03:45 PM
table already exists mussa MySQL 1 July 13th, 2006 03:01 AM
Checking to see if record exists EmmaGale Classic ASP Basics 6 March 14th, 2006 02:39 AM



All times are GMT -4. The time now is 11:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.