joins

Optimizing Multilevel MySQL subqueries (folksonomy and taxonomy)

I was reading the great tagging article by Nitin Borwankar and he started me thinking of the ways to implement differnet levels of searches using two tables. tags { id, tag } post_tags { id user_id post_id tag_id } I started with the simple example of T(U(i)) which means all tags of all users that have an item i. I was ab...

Filter posts by multiple tags to return posts that have all those tags, with good performance

StackOverflow lets you search for posts by tags, and lets you filter by an intersection of tags, e.g. ruby x mysql x tags. But typically it's inefficient to retrieve such lists from MySQL using mulitple joins on the taggings. What's a more performant way to implement filter-by-multiple tag queries? Is there a good NoSQL approach to thi...

How to query values by line with a join?

Hi there, given the two tables and values: Tables People- Columns: [ID]PK Name Field - Columns: [ID FieldName]PK FieldValue Values People ID Name 1 Mary 2 John 3 Tony Field ID FieldName FieldValue 1 Age 20 1 Country USA 2 Age 21 2 Country USA 3 Age 20 3 Country USA I would like a query th...

Where are Cartesian Joins used in real life?

Where are Cartesian Joins used in real life? Can some one please give examples of such a Join in any SQL database. ...

LINQ - How can I use DataSet.DataRelation to join these tables and sum one field?

My LINQ query is not producing the expected output below. Basically, it's the sum of table3.cost corresponding to table2.code and table2.class categorized by table1.alias and ordered by table1.priority. I added two DataRelation's to the DataSet: ds.Relations.Add("Table1Table2", ds.Tables[1].Columns("ID"), ds.Tables[2].Columns("ParentI...

how to change/simplify joins in oracle

I have a join in a oracle query which looks like: FROM eiv.table1 eiv.table2 b WHERE a.state_cd = b.state_code(+) what does the (+) towards the end mean? With this query I have noticed that sometimes I am getting an empty space when records do not match in tables. Is this a left outer join or ri...

rails- creating record in a join table

I'm trying to create a record within a join table from the action of a button. To explain, I would have an events model and would like to track selected events from each user. I used the HABTM relationship since I dont really need any extra fields. User.rb => has_to_and_belongs_to_many :events Event.rb => has_to_and_belongs_to_many :u...

How to create Rails models with multiple complex associations/joins?

I am trying to figure out how to create ActiveRecord models with associations that can yield the same results as this SQL query: SELECT login, first_name, last_name, email_address FROM accounts INNER JOIN people ON person.id = accounts.person_id INNER JOIN email_address_people ON person.id = email_address_people.person_id INNER JOIN ...

Joins - two tables

I am new to Databases. I came across a peculiar problem with two tables. Please let me know the solution. Please fnd the scenario below a ProductCentre table prdcntrId (primary key), prdcntrname a ApplicationType table apptypeid (primary key) prdcntreid(foreign key to ProductCentre ) apptypname ProductCentre table || ...

SQL Joins on varchar fields timing out

Hi, I have a join which deletes rows that match another table but the joining fields have to be a large varchar (250 chars). I know this isn't ideal but I can't think of a better way. Here's my query: DELETE P FROM dbo.FeedPhotos AS P INNER JOIN dbo.ListingPhotos AS P1 ON P.photo = P1.feedImage INNER JOIN dbo.Listings AS L ON P.account...

Many to Many Relationship using Joins

I have a database two tables and a linking table that I need a JOIN query for: Here are my Tables: family (userid (int), loginName, etc) member (memberid (int), loginName(this links member to a family),name, etc) Linking Table: user2member (userid,memberid)...would both be foreign keys? I want to do two things: 1) Be able...

How to exclude rows where matching join is in an SQL tree

...

SQL query to retrieve from three inter related tables

I have three tables specifying important columns below Users(Id, username) Groups(Id, groupname, creator) (creator is the creator of the group) Association(Id, UserId, GroupId) (entries in this table include which user is in which group) Association.UserID =Users.Id, Association.GroupId = Groups.id and also Groups.creator = Users.Id....

Preventing entire JOINed MYSQL query from failing when one field is missing within a WHERE clause

I am doing a couple of joins with a variable in the WHERE clause. I'm not sure if I am doing everything as efficiently as I could, or even using the best practices but my issue is that half my tables have data for when tableC.type=500, and the other half don't resulting in the entire query failing. SELECT tableA.value1 , tableB.value2, ...

In MySQL, what is the most effective query design for joining large tables with many to many relationships between the join predicates?

In our application, we collect data on automotive engine performance -- basically source data on engine performance based on the engine type, the vehicle running it and the engine design. Currently, the basis for new row inserts is an engine on-off period; we monitor performance variables based on a change in engine state from active to...

Speeding up inner-joins and subqueries while restricting row size and table membership

I'm developing an rss feed reader that uses a bayesian filter to filter out boring blog posts. The Stream table is meant to act as a FIFO buffer from which the webapp will consume 'entries'. I use it to store the temporary relationship between entries, users and bayesian filter classifications. After a user marks an entry as read, it w...

PL/SQL - How to pull data from 3 tables based on latest created date

Hello, I'm hoping someone can help me as I've been stuck on this problem for a few days now. Basically I'm trying to pull data from 3 tables in Oracle: 1) Orders Table 2) Vendor Table and 3) Master Data Table. Here's what the 3 tables look like: Table 1: BIZ_DOC2 (Orders table) OBJECTID (Unique key) UNIQUE_DOC_NAME (Document Name i.e...

MySQL Multiple Table Join

I have a 3 tables that I'm trying to join and get distinct results. CREATE TABLE `car` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB mysql> select * from car; +----+-------+ | id | name | +----+-------+ | 1 | acura | +----+-------+ CREATE TABL...

Help with SQL Join on two tables

I have two tables, one is a table of forum threads. It has a last post date column. Another table has PostID, UserId, and DateViewed. I want to join these tables so I can compare DateViewed and LastPostDate for the current user. However, if they have never viewed the thread, there will not be a row in the 2nd table. This seems easy bu...

SQL joining 3 tables when 1 table is emty

I am trying to write a query that connects 3 tables. The first table is info about each festival. The second table is the number of votes for each festival. The third table is reviews for each festival. I want to join all 3 tables so I get all the columns from table1, join table1 with table2 on the festivalid, but I also need to count ...