Skip to content
Advertisement

Tag: sql

How to Troubleshoot Intermittent SQL Timeout Errors

We’ve been having a few instances per day where we get a slew of SQL Timeout errors from multiple applications (System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.) We have over 100 different applications on our network, both web and desktop apps. Everything from VB6 and Classic ASP to

How to get the current effective date in Oracle?

I have a table like the following: TID TName EffectiveDate 1 A 2011-7-1 2 A 2011-8-1 3 A 2011-9-1 4 A 2011-10-1 5 B 2011-8-1 6 B 2011-9-1 7 B 2011-10-1 8 C 2011-9-1 If today is 2011-9-10, I wish the query result will be like this: TID TName EffectiveDate Status 1 A 2011-7-1 Invalid 2 A 2011-8-1 Invalid 3

SQL query to find distinct values in two tables?

I would like to find the distinct Code values and get a return like this: I can’t figure out how to write a SQL query that would return me the above results. Anyone have any experience with a query like this or similar? Answer In proper RDBMS: In MySQL… the UNION removes duplicates

left join returning more than expected

Using the following query table1 returns 16 rows and table2 returns 35 rows. I was expecting the above query to return 16 rows because of the left join, but it is returning 35 rows. right join also returns 35 rows Why is this happening and how do I get it to return 16 rows? Answer LEFT JOIN can return multiple

How can I return pivot table output in MySQL?

If I have a MySQL table looking something like this: company_name action pagecount ——————————- Company A PRINT 3 Company A PRINT 2 Company A PRINT 3 Company B EMAIL Company B PRINT 2 Company B PRINT 2 Company B PRINT 1 Company A PRINT 3 Is it possible to run a MySQL query to get output like this: company_name EMAIL

How do I make the rows of a lookup table into the columns of a query?

I have three tables: students, interests, and interest_lookup. Students has the cols student_id and name. Interests has the cols interest_id and interest_name. Interest_lookup has the cols student_id and interest_id. To find out what interests a student has I do What I want to do is get a result set like where the column name ‘interest_a’ is a value in interests.name

Foreign Key Used in Composite Primary Key

Is it possible to use a composite foreign key as a piece of a table’s composite primary key? For instance, let’s say I have two tables: … and then in a second table, I would like to reference the foreign key in the second table’s primary key: Is there any way that I can do that? Yes, it might be

Get number of values that only appear once in a column

Firstly, if it is relevant, I’m using MySQL, though I assume a solution would work across DB products. My problem is thus: I have a simple table with a single column. There are no constraints on the column. Within this column there is some simple data, e.g. I need to get the number/count of values that only appear once. From

Advertisement