Intersection

Aug 9, 2006

Parwej writes "i have one table, fields are

cs_call_id , fromid , toid , body
----------------------------------
101 1 2 fg
101 3 2 df
101 4 2 fd
101 4 1 dfd
101 3 1 w3e

i would like to find

conversation between
2,3,4

means find the row or 2,3,4 (fromid or toid)"

View 2 Replies


ADVERTISEMENT

Within Table Intersection

Jun 3, 2008

Hello all,
I'm new to SQL and my Teach Yourself in Blah Blah Blah book doesn't index anything helpful to my task. I have a single
TABLE ratings (rid INTEGER PRIMARY KEY, mvid INTEGER, uid INTEGER, rating INTEGER)
with about 100,000,000 rows. I would ultimately like to be able to select rows that are the intersection of two mvid on uid or vice versa -- that is, all rows whose uid is present in the set of rows where mvid=a AND in the set where mvid=b (or vice versa). Something like:
ridmviduidrating
----------------------
1123763
2123314
3123442
4211652
5211764
6211445
7535933
8535762

SELECT * FROM ratings INTO @temp_table WHERE mvid=123
SELECT * FROM ratings WHERE uid IN @temp_table AND mvid=211returns
5211764
6211445

FIRST, I don't know how to accomplish this intersection at all and the only idea I've had is querying the first clause of the intersection and storing it in a temporary/variable table then selecting from that and the original table for the second clause (not that I know how to do this), but I'm afraid this will be very inefficient for the >O(n^2) queries I must perform, so SECOND, should I build derived intersection tables from the results so as to have ~O(1) when repeating the queries later, or will SQL be doing sufficient behind-the-scenes magic? Is there an efficient SQL statement that could generate table(s) of the set of intersections if necessary? Thanks

View 20 Replies View Related

SQL Union / Intersection

Jul 23, 2005

I'm trying to build dynamic sql from a string passed by a callingapplication. Let's assume for this discussion that the user can pass astring of letters with these logical operators ("and", "or", and "andnot") seperating them. Each letter can be rebuilt into a sub querythat will search for people in a table by their middle initial. Forexample,X and Y(select SSN from tblPerson where MiddleInitial = 'X') UNION(select SSN from tblPerson where MiddleInitial = 'Y')This seems pretty easy with the and operator (UNION) but how can I do"or" and "and not"? I remember from a SQL class I had 10 years agothat there was an INTERSECTION operator but it appears that T-SQLdoesn't support it. The closest option is EXIST and NOT EXIST butthese can not be simply inserted between two sub queries (I think),they require the user of a where clause. It would obviously work inthe example above but in the more complecated example below it wouldn'tbe an easy replacement of the operators and sub queries.X and (Y or J) and not LSo, the bottom line is that I have no problem replacing the letterswith the appropriate sub query but I'm looking for a way to replace thelogical operator with SQL syntax that will mimic the logical operator.I hope this makes sense. : )Will Wirtz

View 7 Replies View Related

Deadlock With Index Intersection

Nov 8, 2002

Hi,

I have a deadlock situation with index intersection.

Connection1:

Updates a table T1 which has indexes I1 and I2

Connection2:

Selects from T1 (joining many other tables), SQL Server uses index intersection of I1 and I2.

The deadlock error log shows,

Connection1 has exclusive lock on I1 and waits on exclusive lock request on I2

Connection2 has a shared lock on I2 and waits on shared lock request on I1

Connection2 is selected as the deadlock victim.

The transaction isolation level is explicitly set to READ COMMITTED in ADO connection object.

I don't understand why SQL server needs to hold on the shared lock on I1 while waiting for a shared lock on I2.

Is there any index hint to prohibit SQL server from using index intersection other than explictly using INDEX=I1 or I2.


Thanks

View 3 Replies View Related

Intersection On A Single Table

Nov 12, 2004

Hi all !

I have a table with no keys (temp table) which looks like this :
col1|col2|col3
001|A|.087
001|B|.032
001|C|.345
002|A|.324
002|B|.724
003|A|.088
003|C|.899
001|A|.087
001|A|.234
001|B|.032

As you see, there is some duplicate entries in it. I would like to get a list of all the rows that have the same col1 and col2 BUT different col3 value. The result should return col1=001 col2=A but NOT col1=001 col2=B. I tried a lot of queries with EXISTS, HAVING, etc... but nothing seems to work.

Anyone have an idea how I can do it ?

View 7 Replies View Related

Difference Between Inner Join And Intersection

Aug 14, 2006

Hi Can anybody explain me what is the difference between inner join and intersection?

I prepare a query but it shows the same results then why we need two functions like this to perform same operation

Thanx-Nagu

View 4 Replies View Related

Is It Possible To Use A Where Clause In Select Statments When You Use Intersection?

Apr 26, 2008


Lets say that Dealers have ZipCodes, and that a Dealer can have more than one zipCode, and we want the list of dealers that have both 90210 and 90211 zip codes. BUT we don't want any dealers that have only one of the two ZipCodes in question

What I want to do is something like this

Select DealerID from DealerZips where Zip = '90210'
intersection
Select DealerID from DealerZips where Zip = '90211'

but I get this error msg:
Line 2: Incorrect syntax near 'intersection'




The following sql is silly, but it does run without error
Select DealerID from DealerZips
intersection
Select DealerID from DealerZips

So I am pretty sure my problem is with the Where clauses.

help!

View 3 Replies View Related

T-SQL (SS2K8) :: Split Timedate Range At Intersection

Apr 17, 2014

Using SQL Server 2008 R2

I'm trying to create a report and chart for a a manufacturing resource's activity for a given period (typically 30-90 days)

Jobs are created for the length of the run (e.g. 4 days). If the weekend is not worked and the above jobs starts on a Friday, the resource's activity needs to show 1 day running, 2 days down, 3 days running without the production scheduler having to make it two jobs. (A job can have multiple interruptions due to downtime). I have the jobs' schedules in one table and the downtimes in another (so think of the downtime as a calendar table--non working hours). Unusually, the end time is supplied with the downtime factored in.

So I need the query to create 3 datetime ranges for this job: Fri running, Sat,Sun down, Mon,Tues,Wed Running. Been going round in circles on this for a while. i'm sure there's an elegant way to do it: I just can't find it. I've found several similar post, but can't apply any to my case (or at least can;t get them to work)

Below is some sample date and expected results. I hope the explanation and example data is clear.

-- Create tables to work with / Source and Destination
CREATE TABLE #Jobs
(
ResourceID int
,JobNo VARCHAR(10)
,startdate SMALLDATETIME
,enddate SMALLDATETIME

[Code] ....

Below is some sample data

|--------------------------J1------------------------------------| running
|----D1-----| |-------D2-------| down
|--J1--|----D1-----|-------J1------|-------D2-------|-----J1-----| result

|-----------------J1-----------------------| running
|----D1-------| down
|-----------------J1-----------------------| |----D1-------| result

View 4 Replies View Related

Analysis :: Filter Measure On Intersection Of Dimensions

Jul 24, 2015

SSAS 2008 R2

Is it possible to filter out a measure only at the intersection of Two dimension members? I have a date dimension,  a Hospital dimension and a wait time measure.

For Example, is it possible to filter out Wait time for Bayside Hospital for the Month of June 2015?

I want Wait time to continue to be displayed for all other months and roll up into the totals without the filtered value.

View 4 Replies View Related

Multiple Text Values In Intersection Cells Of Matrix Report

May 30, 2007

I'd like to create a report with the folloiwng format:



DATE1 DATE2 DATE3 DATE4 DATE5 [fixed 5 dates across the top, from today to T+5]

THING1 x x x x

THING2 x x x x

THING3 x x x x

THING4 x x x x



my raw data looks like this:



THING1, DATE1, TEXT VALUE 1

THING1, DATE2, TEXT VALUE 2

&c&c.



Now: there may be 0, 1 or several (by which I mean 2-5 max) text values to display at each intersection. If there are zero I'd like it to be blank, if there are one or several, i'd like to display them in a little list within the cell.



Is this possible?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved