joins

CakePHP: Using two tables for a single model

I'm just picking up development in CakePHP right now so forgive me if this seems obvious; it did to me when I first read about has, belongsTo, hasMany, etc. The problem is I would like to associate two tables with a single model, and was wondering if there was a way to configure this so that when CakePHP did it's queries it automaticall...

CakePHP HABTM: how to find all Photos HABTM multiple Tags?

Hi All, I have two tables, photos and tags, with a standard photos_tags link table. My models show Photos HABTM Tags, and I can update both fine with the links updating too. My question is: say I now want to find all Photos tagged with both "Sunset" and "Ocean" - how do I go about that? I've tried doing an inner join as per Nate's Ba...

Rails: using find method to access joined tables for polymorphic relationships

Ok, I have a generic TimeSlot model that deals with a start_at and an end_at for time spans. A couple models derive from this but I'm referring to one in this question: AppointmentBlock which is a collection of Appointments. I want to validate an AppointmentBlock such that no other AppointmentBlocks have been scheduled for a particular E...

Can you tell me about a decent ruby gem that I can use for complex joins?

Piggy backing off another question I posted, I have a complex find() that changes whether or not a certain id is nil or not. See here: if self.id.nil? blocks = AppointmentBlock.find(:first, :conditions => ['appointment_blocks.employee_id = ? and ' + '(time_slots.start_at between ? and ? or time_slots.end_at bet...

CakePHP: How can I change this find call to include all records that do not exist in the associated table?

I have a few tables with the following relationships: Company hasMany Jobs, Employees, and Trucks, Users I've got all my foreign keys set up properly, along with the tables' Models, Controllers, and Views. Originally, the Jobs table had a boolean field called "assigned". The following find operation (from the JobsController) successf...

joining table of oracle

Hi friends i am having problem in joining two tables in oracle my two tables are shown bellow table1 looks like id Name Jan 7001 Deven 22 7002 Clause 55 7004 Monish 11 7010 Dipesh 55 7070 Dipika 100 table2 looks like id Name Feb 7001 Deven 12 7002 Clause 15 7003 ...

I need help with a SQL query. Fetching an entry, it's most recent revision and it's fields.

Hi there, I'm building a CMS for my own needs, and finished planning my database layout. Basically I am abstracting all possible data-models into "sections" and all entries into one table. The final layout is as follows: Database diagram: I have yet to be allowed to post images, so here is a link to a diagram of my database. Entries ...

How can I write Join statements on dataset..

How can I write Join statements on dataset.. I have data in xml format..I can load that data into a dataset.. but how do i fetch data from two datatables using a join query ...

How can i design a DB where the user can define the fields and types of a detail table in a M-D relationship?

My application has one table called 'events' and each event has approx 30 standard fields, but also user defined fields that could be any name or type, in an 'eventdata' table. Users can define these event data tables, by specifying x number of fields (either text/double/datetime/boolean) and the names of these fields. This 'eventdata' (...

SQLAlchemy & Complex Queries

I have to implement ACL for an existing application. So I added the a user, group and groupmembers table to the database. I defined a ManyToMany relationship between user and group via the association table groupmembers. In order to protect some ressources of the app (i..e item) I added a additional association table auth_items which s...

Help with HQL Query (find duplicates)

I am trying to convert this native sql into an HQL query. Basically it returns all the contacts that are duplicates (by company, firstname, and lastname). The query below works great, but performing a joined subselect seems impossible in HQL is it not?! Select c.* from contact c join ( Select c2.* from contact c2 group by c2.com...

Mysql - Help me alter this search query involving multiple joins and conditions to get the desired results

About the system: We are following tags based search. Tutors create packs - tag relations for tutors stored in tutors_tag_relations and those for packs stored in learning_packs_tag_relations. All tags are stored in tags table. The system has 6 tables - tutors, Users (linked to tutor_details), learning_packs, learning_packs_tag_relatio...

Possible to use _referenceMap with join() on Zend_Db_Select?

Hi All, Example: class Products extends Zend_Db_Table_Abstract { protected $_name = 'products'; protected $_referenceMap = array( 'Bug' => array( 'columns' => array('bug_id'), 'refTableClass' => 'Bugs', 'refColumns' => array('bug_id') ) ); } $obj...

codeigniter active record and mysql

I am running a query with Active Record in a modal of my codeigniter application, the query looks like this, public function selectAllJobs() { $this->db->select('*') ->from('job_listing') ->join('job_listing_has_employer_details', 'job_listing_has_employer_details.employer_details_id = job_listing.id', 'le...

Mysql - help me optimize this query

About the system: -The system has a total of 8 tables - Users - Tutor_Details (Tutors are a type of User,Tutor_Details table is linked to Users) - learning_packs, (stores packs created by tutors) - learning_packs_tag_relations, (holds tag relations meant for search) - tutors_tag_relations and tags and orders (containing purchase det...

how to compare the values inside a table in sql

how to compare the values of same table(say for eg: Order table) each and every time the record get inserted , if the record with same values get inserted already in same table i should not insert the new record with same values. how to do that exactly in sql server 2008 ...

Advice on how to complete specific MySQL JOIN

Hello, I have a mysql table jobs. This is the basic structure of jobs. id booked_user_id assigned_user_id I then also have another table, meta. Meta has the structure: id user_id first_name last_name Here is my php code $sQuery = " SELECT SQL_CALC_FOUND_ROWS job_id, job_name, priority_id, meta.first_name, date_booked ...

Mysql - Help me alter this search query to get desired results

Following is a dump of the tables and data needed to answer understand the system:- The system consists of tutors and classes. The data in the table All_Tag_Relations stores tag relations for each tutor registered and each class created by a tutor. The tag relations are used for searching classes. CREATE TABLE IF NOT EXISTS `Tags` ( ...

Rails named_scope across multiple tables

I'm trying to tidy up my code by using named_scopes in Rails 2.3.x but where I'm struggling with the has_many :through associations. I'm wondering if I'm putting the scopes in the wrong place... Here's some pseudo code below. The problem is that the :accepted named scope is replicated twice... I could of course call :accepted something...

Can this Query be corrected or different table structure needed? (database dumps provided)

This is a bit lengthy but I have provided sufficient details and kept things very clear. Please see if you can help. I am sure a person experienced with this can surely help or suggest me to decide the tables structure. About the system:- There are tutors who create classes A tags based search approach is being followed Tag relatio...