|
I have the following SQL. Tables defined.
#tbContinent ContinentID | ContinentName AddressInCountry AddressID | CountryID AddressInContinent AddressID | ContinentID NameInAddress AddressID | NameID
I then have the following SQL:
--- Insert into tbName...
Started by Gribbler on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
JOIN ( SELECT AddressInCountry.AddressID FROM AddressInCountry UNION --ALL SELECT SELECT n.nameid AS [ID], a.addressid, n.name FROM NAMEINADDRESS t JOIN NAME n ON n.nameid AddressInContinent.AddressID FROM #tbContinent....
|
|
Table: postid|userid|post|replyto
post sql
SELECT * FROM table WHERE postid=12
total replies sql
SELECT COUNT(*) AS total FROM table WHERE replyto=12
the expected result is the "post table" + how many replies to the post. replyto field is the target postid...
Started by mozlima on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Bobby
SELECT postid, userid, post, replyto, det.nb FROM table, (SELECT COUNT....
You could use it as a SubQuery (>5.x only):
SELECT postid, userid, post, replyto, (SELECT COUNT might also work, but right now I don't see how.
|
|
I'm getting odd results from a MySQL SELECT query involving a LEFT JOIN, and I can't understand whether my understanding of LEFT JOIN is wrong or whether I'm seeing a genuinely odd behaviour.
I have a two tables with a many-to-one relationship: For every...
Started by Keith Lawrence on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
The dateid for 10-12 void this mistake in the future... .
In two of your cases, s.DateID is NULL ( LEFT JOIN ) and these are combined together BY or the result of an aggregate operation, and should not be able to be SELECT ed.
BY d.dateID.
|
Ask your Facebook Friends
|
Hi
How would I convert the following to use INNER JOIN rather than nested SELECT?
SELECT [Name].[NameValueID], [Name].[NameTypeID], [Name].[NameID], [Name].[Value] FROM [Name] WHERE Name.NameTypeID IN ( SELECT NameTypeID FROM @tbNameType ) OR Name.NameID...
Started by Gribbler on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
INNER JOIN ( SELECT NameTypeID FROM @tbNameType ) t ON t.NameTypeID=Name.NameTypeID UNION SELECT [Name].[NameValueID], [Name].[NameTypeID], [Name].[NameID], [Name].[Value] FROM [Name] INNER JOIN ( SELECT it:
SELECT....
|
|
Dumb question.. what logic does the database use to determine the result set if you do a select without a join such as:
select * from table1, table2
Started by Marcus on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
More info on this, applied to SQL..
It uses a cartesian product , it gives every possible combination of the two tables .
Each row in table one is matched up to each row in table two .
Cartesian product.
|
|
Hello, I am trying to make an inner join on a select statement like this:
select * from (select* from bars where rownum <= 10 )as tab1 inner join (select * from bars where rownum <= 10 )as tab2 on tab1.close=tab2.close
and I get the following error...
Answer Snippets (Read the full thread at stackoverflow):
SELECT * FROM bars b1 INNER JOIN bars....
See answers to the original question
Not quite sure why you doing that but dont forget you can alias the same table .
You don't have a space between "select" and " " in "select ".
|
|
Hello, I am trying to make an inner join on a select statement like this:
select * from (select* from bars where rownum <= 10 )as tab1 inner join (select * from bars where rownum <= 10 )as tab2 on tab1.close=tab2.close
and I get the following error...
Answer Snippets (Read the full thread at stackoverflow):
join (select * from bars where rownum <= 10 ) tab2 on tab1.close=tab2.close
select * from ((select* from bars where rownum <= 10 )as tab1 inner join (select * from bars where rownum <= 10Just remove....
|
|
Hi, i need select some fields from a table in the query using join, but in the select new statement i dont have acess from the fields of the join table.
var query = from p in persistencia.RequisicaoCompraItems
join s in persistencia.Suprimentos on p.SuprimentoID...
Started by Kaneda on
, 4 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Yes u right but i need
join s in persistencia.Suprimentos on p.SuprimentoID equals s.SuprimentoID
(i need get fields from this join).
|
|
Hi. I've got 2 select statements, returning data like this:
Select 1 col_a col_b
Select 2 col_a col_c
If I do union, I get something like col_a col_b
And rows joined. What i need is getting it like this: col_a col_b col_c
Joined on data in col_a.
Started by Vance on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
SELECT table1.col_a, table1.col_b, table2.col_c ....
SELECT T1.col_a, T1.col_b, T2.col_c FROM (SELECT col_a, col_b, ...etc...) AS T1 JOIN (SELECT col_a, col but not in T2, you can use a LEFT OUTER JOIN instead.
|
|
I have two separate SELECT statements:
SELECT VCe.VId FROM `VCe` WHERE `YId` = 9007 AND `MaId` =76 AND `MoId` = 2851 SELECT r_pts.p_id FROM r_pts WHERE r_pts.v_id IN (57202, 57203, 69597, 82261, 82260, 69596, 69595, 82259)
When they are run separately...
Answer Snippets (Read the full thread at stackoverflow):
Illustrating "how to include WHERE conditions in a JOIN ":
SELECT r.p_id FROM r_pts r INNER JOIN VCe vSELECT r_pts.p_id FROM r_pts, 'VCe' WHERE r_pts.v_id = VCe.VId AND VCe.YId = 9007 AND VCe.MaId =76 AND VCe.MoId = 2851
The basic....
|