I am working with django and having a hard time grasping how to do complex queries
Here is my model
class TankJournal(models.Model):
user = models.ForeignKey(User)
tank = models.ForeignKey(TankProfile)
ts = models.DateTimeField(auto_now=True)
title = models.CharField(max_length=50)
body = models.TextField()
cla...
I have two tables say A and B.
A cols are GUID, someintVar, someMoreIntvar
B col are GUID, someItemNO, SomeItemDesc
Now for one GUID I will have only one row in Table A. But I can have multiple rows for the same GUID.
Now I want to query the database based on GUID and select values in a class.
This class will have a list that will hold ...
Hello
I am trying to use my join table "showing" to get a list of movies
I was trying to use this code but it does not work.
@showing_list = Showing.find_sorted_showings("time")
@movie_list = @showing_list.movies <-- NoMethodError
Here is my Showing class
class Showing < ActiveRecord::Base
belongs_to :movie
def self.find_s...
Hi Guys,
Im trying to join a number of elements of an array into a string using this;
$a = "h","e","l","l","o"
$b = [string]::join("", $a[0,1,2,3])
But I get a 'Missing ')' in method call' error. The join documentation only mentions joining all the elements of an array, not elements at specific indexes. Can this be done?
Cheers
And...
I have 2 tables in SQL.
Table 1
Step Id
Step Name
Table 2
Profile Id
Step Id
Completed
I would like to return the following results even if there is not match in table 2:
Results
Table1.Step Id
Table1.Step Name
Table2.Profile Id
Table2.Completed
The way I am doing this in SQL is the following:
select * from [Table 1] t1
left joi...
Here are my models:
class Deck < ActiveRecord::Base
belongs_to :game
has_many :deck_cards
end
class DeckCard < ActiveRecord::Base
belongs_to :card
belongs_to :deck
end
class Card < ActiveRecord::Base
end
Here's my attempted find:
DeckCard.all :joins => [:card, :deck], :conditions => {{:decks => {:game_id => @game.id}}, {:ca...
I have the following sql statement:
SELECT TOP (100) PERCENT inv.CompanyID,
cust.CustID AS ClientID,
cust.CustName AS CustomerName,
inv.InvcKey, inv.PrimarySperKey AS SperKey,
inv.TranID AS InvoiceNumber,
in...
Hi all:
I was wondering if anyone has tried to do this in NHibernate.
I have the following tables (simpify version).
CITY:
city (varchar2) (PK)
province (varchar2) (PK)
CITY_TL:
city (varchar2) (PK)
province (varchar2) (PK)
lang (char (2)) (PK)
LOCATION:
location (varchar2) (PK)
some other column.
As you can see, there are no relat...
Overview:
I have three tables 1) subscribers, bios, and shirtsizes and i need to find the subscribers without a bio or shirtsizes
the tables are laid out such as
subscribers
| season_id | user_id |
bio
| bio_id | user_id |
shirt sizes
| bio_id | shirtsize |
And I need to find all users who do not have a bio or shirtsize, ...
I have two tables:
Patient
pkPatientId
FirstName
Surname
PatientStatus
pkPatientStatusId
fkPatientId
StatusCode
StartDate
EndDate
Patient -> PatientStatus is a one to many relationship.
I am wondering if its possible in SQL to do a join which returns only the first two PatientStatus records for each Patient. If only one Patien...
I've got the following request :
select *
from tbA A, tbB B, tbC C, tbD D
where
A.ID=B.ID and B.ID2= C.ID2 and A.ID=D.ID and C.ID3=D.ID3 and B.ID4=D.ID4
and
A.Foo='Foo'
I've heard several times that this join syntax is depreciated, and that I should use the 'JOIN' keyword instead.
How do I do that in such a complicated ...
Hi,
I'm working on an assignment where I'm supposed to compare different join methods in SQL Server, namely hash-join, merge-join and index-join.
I'm having difficulties getting SQL Server to perform an index-join. Can anyone show me how I can force it to use an index-join (using a join hint or similar), or just simply provide a simpl...
I am facing a performance (it can lead to scaling issue later on) issue at the moment. The application I am working on is quite complex and it’s running on SQL Server 2005, I need to join 6 - 7 tables to get the desired data. Each table contains more than 100,000 rows of data so far. The database schema can not be changed (must stay as i...
I have two hibernate entities User and Blog. User can be interested in multiple Tags. Blog can belong to multiple Tags. For a User, How do i find the Blogs which belong to the Tags the User is interested in?
I need something like
Select * from Blog where Blog.Tags IN User.Tags
except that SQL or HQL doesnt allow such comparisons in ...
This follows this prior question, which was answered. I actually discovered I could remove a join from that query, so now the working query is
start_cards = DeckCard.find :all, :joins => [:card], :conditions => ["deck_cards.deck_id = ? and cards.start_card = ?", @game.deck.id, true]
This appears to work. However, when I try to move th...
We have a table that is going to be say 100 million to a billion rows (Table name: Archive)
This table will be referenced from another table, Users.
We have 2 options for the primary key on the Archive table:
option 1: dataID (bigint)
option 2: userID + datetime (4 byte version).
Schema:
Users
- userID (int)
Archive
- userID
- d...
I'm toying with the idea of writing a physics simulation software in which each physical element would be simulated in its own thread.
There would be several advantages to this approach. It would be conceptually very close to how the real world works. It would be much easier to scale the system to multiple machines.
However, for this t...
FROM [TABELA DE PRODUTOS/ESTOQUE] AS T1
, [TABELA DE PRODUTOS] AS T2
, [TABELA DE MOVIMENTAÇÃO DE ESTOQUE] AS T3
, [TABELA DE FORNECEDORES] AS T4
, [TABELA DE PRODUTOS/ESTOQUE] AS T5
WHERE (((T1.Produto)=[T2].[ID])
ETC
So, how can I add a JOIN between those tables ? I need a left join, like:
FROM [TABELA DE PRODUTOS/ESTOQUE] <- TABLE...
I'm having some trouble with a tricky SQL-query.
In my MySQL database there is the tables topics, tags and tags_topics to join them.
I want to fetch topics that share the same specified tags. For example, let's say i have 3 tags with ids 1, 2 and 3, i want to fetch all topics that have tag 1, 2 and 3 associated to them. The topics can ...
Can anyone explain to me what is wrong with my query?
SELECT T2.TIPOPRODUTO
, T2.PRODUTO
, T1.ESPESSURA
, '' AS LARGURA
, '' AS COMPRIMENTO
, '' AS [ACABAM REVEST]
, '' AS [ESPECIF QUALIDADE]
, T1.CÓDIGORASTREABILIDADE
, T3.DATA
, T4.NOMEFANTASIA
, T7.NOME
, T5.DT_INICIO_RESERVA
, T1.PESO
...