SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sub query help.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bob21
Starting Member

1 Posts

Posted - 05/02/2012 :  06:29:33  Show Profile  Reply with Quote
i am write a single query which displays all brokers who allowed
shareholders to buy or sell more than 50,000 shares per trade

This is what i have done so far using a correlated sub query

SELECT b.first_name ||' '|| b.last_name AS "BROKER"
FROM  brokers b  INNER JOIN trades t ON b.broker_id=t.broker_id
  INNER JOIN 
      (SELECT t.broker_id, shs.share_holder_id     
      FROM share_holder_shares shs   
  INNER JOIN trades t ON shs.share_holder_id = t.share_holder_id 
  INNER JOIN brokers b ON b.broker_id = t.broker_id 
  WHERE shs.amount > 500000
  GROUP BY shs.share_holder_id) b1
 transaction_types ON b1.type_id = transaction_types.type_id;


i can 't seem to display the correct info as i keep getting the error 'missing keyword'?? :/

also how does the insert image work on the forum, i have an image of my er diagram that i want to show.

DonAtWork
Flowing Fount of Yak Knowledge

2111 Posts

Posted - 05/02/2012 :  06:36:46  Show Profile  Reply with Quote
The pipes are not T_SQL code. Are you using oracle or MySql? This forum is exclusively for MS SQL SERVER (Transact SQL).

These guys take care of a LOT of different systems: http://www.dbforums.com/









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

vijays3
Constraint Violating Yak Guru

India
311 Posts

Posted - 05/02/2012 :  10:22:21  Show Profile  Reply with Quote
quote:
Originally posted by bob21

i am write a single query which displays all brokers who allowed
shareholders to buy or sell more than 50,000 shares per trade

This is what i have done so far using a correlated sub query

SELECT b.first_name ||' '|| b.last_name AS "BROKER"
FROM  brokers b  INNER JOIN trades t ON b.broker_id=t.broker_id
  INNER JOIN 
      (SELECT t.broker_id, shs.share_holder_id     
      FROM share_holder_shares shs   
  INNER JOIN trades t ON shs.share_holder_id = t.share_holder_id 
  INNER JOIN brokers b ON b.broker_id = t.broker_id 
  WHERE shs.amount > 500000
  GROUP BY shs.share_holder_id) b1
 transaction_types ON b1.type_id = transaction_types.type_id;


i can 't seem to display the correct info as i keep getting the error 'missing keyword'?? :/

also how does the insert image work on the forum, i have an image of my er diagram that i want to show.



If it is Sql server Try this .

SELECT b.first_name +' '+ b.last_name AS "BROKER"
FROM  brokers b  INNER JOIN trades t ON b.broker_id=t.broker_id
  INNER JOIN 
      (SELECT t.broker_id, shs.share_holder_id     
      FROM share_holder_shares shs   
  INNER JOIN trades t ON shs.share_holder_id = t.share_holder_id 
  INNER JOIN brokers b ON b.broker_id = t.broker_id 
  WHERE shs.amount > 500000
  GROUP BY shs.share_holder_id) b1
 transaction_types ON b1.type_id = transaction_types.type_id;

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 05/03/2012 :  10:21:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You have two aliases b1 and transaction_types for derived table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47091 Posts

Posted - 05/03/2012 :  14:45:49  Show Profile  Reply with Quote
quote:
Originally posted by madhivanan

You have two aliases b1 and transaction_types for derived table

Madhivanan

Failing to plan is Planning to fail


I think its a copy paste typo from original query

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 05/04/2012 :  06:19:16  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

You have two aliases b1 and transaction_types for derived table

Madhivanan

Failing to plan is Planning to fail


I think its a copy paste typo from original query

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Then the query should work fine in Mysql

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000