Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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.

 
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
 
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

 
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




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





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