October 21, 2009 at 12:45 pm
I need to be able to query a database to find records that meet BOTH of the following conditions below:
SELECT * FROM SoftwareProduct where Productname='Internet Information Services' and ProductVersion like '7%'
SELECT * FROM Services_DATA where DisplayName0 like 'FTP Publishing Service'
How can I do this?
Thanks!
October 21, 2009 at 12:51 pm
winsysadmin (10/21/2009)
I need to be able to query a database to find records that meet BOTH of the following conditions below:SELECT * FROM SoftwareProduct where Productname='Internet Information Services' and ProductVersion like '7%'
SELECT * FROM Services_DATA where DisplayName0 like 'FTP Publishing Service'
How can I do this?
Thanks!
Is there any common field in these two tables?
---------------------------------------------------------------------------------
October 21, 2009 at 1:00 pm
There is no common field.
October 21, 2009 at 1:25 pm
nothin here, please move on. Some technical glitch!
---------------------------------------------------------------------------------
October 21, 2009 at 1:27 pm
Please dont think I am doubting/underestimating your sqlserver database understanding. Just wanted to know if you understand these things please?
1. First query returns the rows from softwareProduct table where product name is IIS and ProductVersion starts with 7
2. Second query returns rows from services_DTA table where displayname = 'FTP Publishing Service'
Now if both the queries return the same number of columns, then you put 'UNION' between these two queries so that you have one result set, something like,
SELECT * FROM SoftwareProduct
where Productname='Internet Information Services'
and ProductVersion like '7%'
UNION
SELECT * FROM Services_DATA
where DisplayName0 like 'FTP Publishing Service'
If you want to return records which satisfy both the conditions, it means
1.you need to have a table where all these three columns are there. Or
2.Its in two different tables but two tables are connected by a common field. In this case we can connect the two tables on this common field and then fetch the records which matches both the conditions.
Please give the table definitions and from which table you want to query the data. Thanks
---------------------------------------------------------------------------------
October 22, 2009 at 5:31 am
You can simply run both queries within a single stored procedure and then deal with the multiple result sets on the client side.
I don't see any other options since the two queries you're showing don't seem to be related in any possible way.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply