SQL queries  doubts -asking for help again

Hi all,
I have been trying to design a schema with all objects needed.Infact,i have completed with all tables and inserting data
in them.
But,am very confused and mixed with the RELATIONSHIP between tables because now when i have to retrieve data-then
writing proper query ..correct one is a complicated procedure.
I feel since i am very new to this,the design hasnt been effecient.
Scenario has a specific table with employees, departments, and projects.
employees
eid ename Salary               
1 Emp1 1000          
2 Emp2 100
3 Emp3 189
4 emp4 200
5 emp5 300
6 emp6 400
departments
**each department has one manager
DEPTid     NAME          LOCATION           mgrid     
10       ACCOUNTING       NEW YORK     0
20        RESEARCH       DALLAS          1
30        SALES       CHICAGO      2
40        OPERATIONS       BOSTON          3RELATIONSHIP Table for employee nd department and Manager ---->created seperate table as 1 :M relationships
(**one person can belong to multiple departments )
EMP_mngr_dept
E_ID     DEPt_ID     mgrid     
1     10     200
208     50     121
1     30     114
121     20     201
114     10     200**Projects table
There are many projects owned by different deparments.A project can belong to only 1 department.
PROJECT_NAME           PROJECT_STATs     PROJECT_ID     PROJECT_FROM_DT_TM     COST                   DEPARTMENT_ID
ACCOUNT_PRO          Active                1          2/17/1996          2000000                    10
MMC_PRO                          Active          2          2/20/2006          20000000                    20
STUDENT_MANAGEMENT     Active          3          2/25/2007          2000000          40***Relationship table employees and projects
A person can be in many projects at a time
EMP_project_Rltn
PROJECT_ID     EMPLOYEE_ID     START_DATE     END_DATE
1          1          
2          1          
1          208          
2          208          
5          10          2/21/2009 3:45:53 AM     (1)QUERY to MOVE A PERSON FROM ITS EXISTING DEPARTMENT TO ANOTHER DEPARTMENT.
Does this mean that even the PROJECT info for the person changes when he moves to another dept?What woulc be the query then?
(2)Show details of person, his managers , departments and project he works.
is the below join proper? Please advise me ....if i have used many extra tables for this.
select * from employees e, EMP_mngr_dept emd,departments d,EMP_project_Rltn p,
projects p1
where e.employee_id =1
and emd.employee_id = e.employee_id
and emd.department_id =d.department_id
and p.employee_id = e.employee_id
and p1.project_id = p.project_id
PLEASE PLEASE ADVISE AND HELP ME IF THE ABOVE TABLES CREATED ARE MUST NEEDED AND EFFICIENT FOR MY SCENARIO.i AM VERY CONFUSED WITH THE NO OF TABLES REQUIRED.
query to find expenditure of all projects together in terms of salary.
(3)SQL to be able to show a person--->manager-->and their manager's MANAGER
(4)How will managers to view all employees reporting to him.
Edited by: [email protected] on Feb 23, 2009 2:55 AM
Edited by: [email protected] on Feb 23, 2009 3:43 AM

Hi,
user_7000011 wrote:
(3)SQL to be able to show a person--->manager-->and their manager's MANAGER
select * from employees where employee_id in (
select manager_employee_id from emp_manager_dept where employee_id =****)
Start by showing a person and his managers. (Once you learn how to do this, adding the managers' managers will be easy.)
Pretend that the person is in one table (let's call this table p), and their managers are in another (let's call it m).
You can get all the information you need about the person using a query on table p.
You can find who that person's managers are (just their id's) by joining p to emp_mgr_dept.
You can find all the information about those managers by joining table m.
So this is a three-way join: no sub-queries are needed. All the join conditions are simple equi-joins, such as "p.eid = emd.e_id".
Since p and m are really the same table (employees), the FROM clause will contain two copies of employess, one with the alias p, the other aliased m.
Notice that the query invloves three tables, but you do not need to display any columns from one of them. This happens a lot.
(4)How will managers to view all employees reporting to him.
select * from employees where employee_id in
(select employee_id from emp_manager_dept where manager_employee_id in
(select employee_id from employees where first_name ='***'))
This is very similar to the problem above. I would solve this problem the same way, with a three-way join.The main difference is that you are starting with the manager's name, not the person's name. The relationships between the tables are the same.
Another minor difference is that you do not need to display any information from the m or emp_mgr_dept tables. This is a little more unusual, but not really different from, the problem above, wherre the SELECT clause referenced two tables out of three.
You could also use sub-query to solve this problem, but I don't recommend it.

Similar Messages

  • Even I cant believe this is happening again! i'm once again asking for help with my account.  Since im very sick I ask that u look into my account and read the hell verizon has put me through and assist ending the hell once and for all even if that means

    Even I cant believe this is happening again! i'm once again asking for help with my account.  Since im very sick I ask that u look into my account and read the hell verizon has put me through and assist ending the hell once and for all even if that means ending my contract, i just want the hell over. I went into my bill tonight and the mess was still there I paid $110. that's what I owe

    I guess I spoke too soon!  I really can't believe this nightmare is not over yet! My account is still wrong.  The credit that I was due totaled $63.00  I am looking at a message on my phone saying that $21.01 was credited which makes my balance $219.72.  I received a text the following day that says, I processed your credit of $30.00 and your new balance $216.73 how is that possible?  None of the late fees were credited and the amount due for my monthly charges are wrong.  Before any changes were made to my data plan back in Nov. My monthly charges were $140.00, I needed my hot spot back and i was told that the hot spot will increase my bill $10 for each phone that totals $20.  The customer rep that change my data plan at that time also gave me a credit of $20 to compensate for the increase until I had time to talk with customer service about the mix-up with my Hot spot. I originally had the hot spot, but the rep that change my plan almost a year prior told me nothing was changing except I was getting more for less money.  I explained to that rep that I need my hot spot 4 times a year...and I don't want my plan to have any changes. To verify what I'm telling u check my account and see that I called from Albany New York wanting to know where my hot spot was and I was told I didn't have the hot spot on my account since the last data change!  I lost money once again due to the verizon rep's.  so my current data plan the rep promised would increase $20 which makes my monthly charges that were $140 prior to the change $160 after the hot spot was returned to my account.  Then I was given a $12 credit per month for 12 months because of so many mistakes made to my account so with that $12 credit my monthly charges should $148 + surcharges + taxes and that's not what I see. I do know this much right now my account is in such a shambles I can hardly see the light at the end if there is an end!  I need real help!
    >> Personal information removed by Verizon Moderator to comply with the Verizon Wireless Terms of Service <<

  • I've authorized my iPhone on a Mac but when I go to play videos it asks for authorization again, only to tell me that I have authorized too many computers. Help!

    So I used my work Mac to authorize my iPhone so I can play music, but now that I want to play a movie it asks for authorization. I've already authorized that account! I don't understand why it's asking for authorization again when I want to play a movie. Plus, I can't access the iTunes store from my work computer, so I'm stuck until I go home to deauthorize my other computers. Why is this happening?

    Authorization does not apply to iphones.  Authorization is for computers.
    About iTunes Store authorization and deauthorization

  • My new ipod touch 4g doesn't let me download apps, it just says type in Apple ID password and when i do it asks for it again and again and again....

    My new ipod touch 4g doesn't let me download apps, it just says type in Apple ID password and when i do it asks for it again and again and again.... what should i do?

    I've got the same problem as well. When i connect all i see is "set up your iphone" screen. It worked perfectly fine a couple of weeks back when I last synced but, doesn't sycn anymore.
    Any help would be appreciated.

  • HT201363 Sir/Madam,  can I ask for help to know what's my secret questions and answer in my apple ID? Coz i'm not the one who make my apple ID when i first buy my phone. I can't ask my friend On what he put in my secret questions coz i'm already here in p

    Sir/Madam,
    can I ask for help to know what's my secret questions and answer in my apple ID?
    Coz i'm not the one who make my apple ID when i first buy my phone. I can't ask my friend
    On what he put in my secret questions coz i'm already here in philippines right now and my friend who made my apple ID is still in bahrain.. I wish i could get a feedback through this matter. Thanks and i'm kyztle Romanes . Thanks you so much i wish i'd get any feedback to your side.. I wanna purchase a builder in my clash of clans account coz my clanmate philip sent me a gift card for 25$ that's why i need your help.. Thanks again Apple company..
    Sent from my iPhone
    On Jan 1, 2014, at 4:53 PM, iTunes Store <[email protected]> wrote:
    $25
    Buy that builder
    Philip sent you an iTunes Gift
    You can redeem this gift on your iPad, iPhone, iPod touch, or on your computer using iTunes. Once you redeem your gift and verify your Apple ID, you will be credited with $25 and can purchase the latest music, apps, and more.
    Valid only on iTunes Store for U.S. Requires iTunes account and prior acceptance of license and usage terms. To open an account you must be 13+ and in the U.S. Compatible software, hardware, and Internet access required. Not redeemable for cash, no refunds or exchanges (except as required by law). Code may not be used to purchase any other merchandise, allowances or iTunes gifting. Data collection and use subject to Apple Customer Privacy Policy, see www.apple.com/privacy, unless stated otherwise. Risk of loss and title for code passes to purchaser on transfer. Codes are issued and managed by Apple Value Services, LLC (“Issuer”). Neither Apple nor Issuer is responsible for any loss or damage resulting from lost or stolen codes or use without permission. Apple and its licensees, affiliates, and licensors make no warranties, express or implied, with respect to code or the iTunes Store and disclaim any warranty to the fullest extent available. These limitations may not apply to you. Void where prohibited. Not for resale. Subject to full terms and conditions, see www.apple.com/legal/itunes/us/gifts.html. Content and pricing subject to availability at the time of actual download. Content purchased from the iTunes Store is for personal lawful use only. Don’t steal music. © 2012 Apple Inc. All rights reserved.
    Apple respects your privacy.
    Information regarding your personal information can be viewed at https://www.apple.com/legal/privacy/.
    Copyright ©2014 Apple Inc. All rights reserved.
    <Email Edited by Host>

    It is a phishing attempt to get your Apple ID and Password.
    You should forward it to Apple : [email protected]

  • Problem with A300, Ask for help

    Hello from Bulgaria!
    In the beginning I want to apologize if I bother you at the wrong place. This was the only place i found in all your sites at "Contact us" menu. If I'm in mistake please redirect me to the right e-mail or topic.
    I have extremely big problem with one of your products, and I'm afraid I can't solve him without your help. Few months ago I bought a laptop witch exact model is TOSHIBA SATTELITE PRO A300 - 1GQ. Model No.: PSAG1E - 00900NF3, Serial No.: 88549776Q. If you need another information I can tell you everything. Badly i got serious virus and the situation reach fall windows start. I know about integrated Toshiba Recovery and I used it. Windows Vista was successfully installed but the partion was not formated. Some of the system files was still corrupted and I resorted to Toshiba DVD comming with the laptop. I ran it, there was no problems until I saw Windows XP logo. I was pretty surprised because I expected Windows Vista like original one which came with the laptop from the shop. Another problem was that that installation formated whole HDD including partitions different from C:\ with Windows system files. All of my data is gone without I could be able to do something. However, th
    e question is that I need Windows Vista very badly and I dont want XP. I tried to use hidden partition with Toshiba recovery again but I cant no longer access it. So I left with original XP with drivers integrated with it. The problem is that I need Vista with integrated drivers. It wouldn't be hard also if I found that drivers in your sites. Nowhere in your sites with download I could find the exact model to take it. The nearest was A210 which I think is pretty far from mine.
    And it the end I ask for help if you can tell me where to download the needed drivers or anyway to put Vista back. Preliminary I thank you and I apologize again for the disturbing. I need that information badly and I don't know where I can get it from. At least show me valid e-mail to contact with Toshiba Support.

    Satellite Pro A300-1GQ 
    This was the only place i found in all your sites at "Contact us" menu. If I'm in mistake please redirect me to the right e-mail or topic.
    These forums are for United States computers. For that European machine, you probably want to post elsewhere.
       Toshiba Support Forums Europe 
    You need to obtain a recovery disc that restores the hard drive to factory-new.
    -Jerry

  • Hello! I bought an iphone on ebay. I feel the introduction says that is not a service. need to unlock official data on where the contract but I am not asking for help

    Hello! I bought an iphone on ebay. I feel the introduction says that is not a service. need to unlock official data on where the contract but I am not asking for help

    I'm sorry but your post doesn't make much sense in English. You may want to try posting again in your native language.
    Best of luck.

  • Deception, no or few replies to people asking for help

    I'm so sad about this new forum. There are many questions asked and few replies or replies that don't go deep.
    I remember that in the old forum there were very interesting discussions, very deep (technically speaking), I always found a solution or at least I found out that I wasn't the only one to have that bug/problem.
    I could read some of the discussions, even if I didn't have that particular problem, only because they could teach me something.
    Now it is difficult to follow what the people ask and what others reply. It's a sort of chat with 20 people who ask for help during the same minute.... how to follow that How to help?

    Patrizia Franchini wrote:
    And remember also that in Europe Apple and the Mac are not so important (or weren't before the iDevices). In the shops you couldn't find ONE webcam compatible with your Mac, ONE software for the Mac, ONE book, .. It was necessary to order the items on the Internet. No version of the State tax program for the Mac,... It is/was a fight, a challenge.
    It was the same way in the US before the Apple Stores. There is nothing Apple can do about tax software. Contact the company that makes it and ask for a Mac version.
    Here the price difference with the PC are enormous... in the United States the prices are more competitive.
    Because the US doesn't have a VAT. I've been to Europe many times. Everything is more expensive there. I live in Canada now and it is much the same here. Currency exchange rates are meaningless. Everything is more expensive in Canada. If anything, Apple products are actually marked up less than other products.
    And you also have some privileges: there are many promotions only available in the United States. You lose all your purchased music? In the United States there is a way to have it back with a click, but not in Europe. In your iTunes store there are many free songs and video,.... In Europe it's only a year or two that there is ONE free song each week.
    I sincerely doubt Apple is responsible for that. Europe is a huge, wealthy market. Apple would love to offer Europeans the same deals that they do in the US. It has taken years for Apple to make agreements with all of the various rights holders to make iTunes the market that it is. Compare iTunes to the iBookstore. These things just take time. The European companies just don't want to make any deals.
    Well, just to explain why Apple has/had a little part of the market here, and why it is/was difficult to find Apple products and help for Apple products.
    Keep in mind that Apple's newfound success is due to its intense focus on devices for consumers. The PC industry is still 85% PC. Just try to use a Mac at work. I dare you. Given the entreprenurial nature of the US vs the heavily industrial nature of Europe, I can see why it would be worse there.
    I forgot to say that to obtain help from Apple is very difficult where I live. No phone service from Apple, no chat with the customer care, no Genius bar (or very far away, 300 km), no companies that can help you if you lose your data from the hard disk. The Apple Store is in German and French and customer service people only speak French and German, and not Italian. If you want to speak Italian, you must contact the Italian Apple Store, but they can't help you with a problem in the Swiss Apple Store.
    You have to find yourself the solution.
    It is the same everywhere. Apple Stores are only in major markets. Many people in the US or Canada still have to drive 300 km to find one. I can't help much with the language. There are something like 500,000 Italian speakers in Switzerland. How many of them own Macs? If Apple hired some Italian speaking customer care representatives would they then have to increase the price for Apple products for everyone in Switzerland?
    The best option for avoiding data loss is Time Machine.

  • I am writing to this forum to ask for help in determining whether Aperture will satisfy my needs when I switch from Windows to MAC in the near future.

     I am writing to this forum to ask for help in determining whether Aperture will satisfy my needs when I switch from Windows to MAC in the near future.  
    I am currently using Photoshop Elements 8 on Windows 7.  After several years of use, I am self taught and adequately proficient for an amateur.  What I didn't realize (until I started researching my upcoming migration on the Internet) is that I actually use PE8 for two functions: digital asset management and digital editing. 
    Regarding Digital Asset Management: My research leads me to understand that PE on MAC does not provide the same level of organizational capability that I am used to having on Windows, instead providing Adobe's Bridge which does not look very robust.  Furthermore, iPhoto, which come on MAC will not support the hierarchical keyword tagging that I require to organize my library of photos. The two SW applications which I am thinking of switching to are either Aperture or Adobe's Lightroom.  Frankly, I'm thinking that it would be smoother to stay within the Apple product line. 
    So the remaining question is whether Aperture will support my digital editing needs. The tweaks that I do to my photos are not very complex (no, I do not want to put people's heads on other animal bodies).  But could someone who uses Aperture tell me whether It will allow me to do the following kinds of edits?:
    - If I have a photo where someone's face is too shadowed, can I lighten just that person's face, and leave the rest of the photo as-is?  
    - if I have a photo where the background is cluttered (eg, 2 people in front of the Parthenon which is undergoing renovation), can I remove just the construction cranes?  
    - Can it splice together several separate photos to give a panoramic?  
    If, once I get Aperture, I find that it cannot enable the kinds of editing that I do, I would probably get PE11 in the future. However, if people in this forum tell me that Aperture will definitely not  support the kinds of editing which I've described in the previous paragraph, I would prefer to get PE11 with my initial configuration (since someone will be helping me with my migration).  
    Thanks in advance for your consideration and help! 

    I am concerned, however,  about using a non-Apple Digital Asset Manager in OSX. I would really like to avoid integration problems. Is using PE11 to import and catalog my digital photos likely to cause conflicts?
    Thanks for any insight on this
    Amy,
    Not so much conflicts as maybe a little less seamless integration with Apple software and perhaps some third-party software providers in the Mac App Store where some programs build in direct access to iPhoto and Aperture libraries for getting images into those programs easily. Typically, there is a manual command to go to Finder (think Windows Explorer) to browse folders.
    One caution to mention however, is that the organization you set-up in PE Organizer is unlikely to transfer over to either iPhoto or Aperture if you decide to change at some point.
    The only real stumbling block that I see in your opening comment is that you want hierarchical keywording (Kirby or Léonie can go into the details on keywording limitations as I stay at one level). If you can work with the keywording schemes of either iPhoto or Aperture, then using PE for your external editor (either program supports setting an external editor) would probably be ideal since you know PE well. This is the idea with the Mac App Store version of PE (editor with no organizer).
    Note - I use Photoshop CS6 (full version) with Aperture and it works really well. The only downside is that Aperture has to make either a TIFF or PSD file to send to an external editor so that the original file is protected by not sending it to the pixel editor. While TIFF or PSD files protect the integrity of the image information without degrading it, they are typically much larger file sizes on disk than either RAW or JPEG files. Therefore, your library size (iPhoto or Aperture) will balloon quite a bit if you send a lot of files to external editors.
    One other possibility for an external editor would be a program called Pixelmator. It is pretty similar to early versions of Photoshop, but built for Mac. Other than the panoramics you want, it will do most pixel editing that PE can do. It is not an organizer, so it is built to go with either iPhoto or Aperture. It does have differences in how you complete certain procedures, so there is bit of a learning curve when you are used to doing it the Adobe way.

  • My iphone4s was stolen, how do I want to come back, ask for help产品序列号(SN)   013189003958713

    My iphone4s was stolen,how do I want to come back, ask for help .the product serial numble 013189003958713

    The only way to locate/disable/erase any lost/stolen iPhone is through Find My Phone or a similar app. However, this requires that Find My Phone be setup/activated, on your phone, before it was lost/stolen. You would then login at iCloud.com & try to locate it. This requires the phone be turned on & have an Internet connection. There is no other way to locate a lost/stolen iPhone. Apple can't/won't help you, nor will your carrier. Report the loss to the Police, your carrier & Insurance company. Change all of your passwords.

  • I have a mac OSX desktop version 10.6.8 and all of a sudden I can't get a full screen view in Safari when I ask for help the response is use the arrows on the top right of the screen ... I don't have them  ... can anyone help?

    I have a mac OSX desktop version 10.6.8 and all of a sudden I can't get a full screen view in Safari when I ask for help the response is use the arrows on the top right of the screen ... I don't have them  ... can anyone help?

    Hi Mary,
    I don't remember those arrows in 10.6, only 10.7 & up!?
    I have 10.6.8, as you do. To make your Safari full screen, make sure you have the left hand side of your safari page moved  all the way to the left.  Then move your cursor to the BOTTOM RIGHT CORNER of the safari page, and simply drag your page towards the lower right hand corner of the screen. NOTE: you will see a series of lines on the bottom right corner of the page, indicating where to place you cursor arrow.
    By wuzradioman here...
    https://discussions.apple.com/thread/4218928?start=0&tstart=0

  • I am at starbucks and when I try to download my free music on itunes, my password is always rejected, even when i am forced to create a new one!!!  what am I doing wrong, who do I ask for help

    I am at starbucks and when I try to download my free music on itunes, my password is always rejected, even when i am forced to create a new one!!!  what am I doing wrong, who do I ask for help?

    Due to recent security issues and identify theft (mostly due to phishing scams), the iTunes Store seems to be requiring more frequent verification of credit card information when a card is registered in your account, even if you have a balance from a prepaid card. Either just go through the verification process or, if you have a credit card entered and you don't expect to need the card anytime soon, go into the Payment information in your account and set the payment method to "none" which should then stop the regular requirements for verification  (it may still ask - mine does - but you should just be able to click through the buttons without problems).
    Hope this helps.

  • I cannot retrieve my emails on my Mac Book Pro operating on 10.7.3 Icloud was already workingit keeps asking for password and when i put correct password in it keeps asking for it again and again. This has just started today

    I cannot retrieve my emails on my Mac Book Pro operating on 10.7.3 Icloud was already workingit keeps asking for password and when i put correct password in it keeps asking for it again and again. This has just started today

    Though it's unlikely to be wrong if things were set up properly in the first place, as a check go to Mail Preferences>Accounts and check that the server setting for IMAP (incoming) is imap.mail.me.com (not just mail.me.com).
    Your next step either way would be to go to System Preferences>iCloud and sign out, then sign back in again. (You can ignore warnings about data disappearing - your calendars etc. will disappear when you sign out but reappear when you sign back in).

  • SOME OF MY MUSIC I HAVE ALREADY PAID FOR IS ASKING FOR PAYMENT AGAIN

    Hi,
    I recently got a new iphone and my most recent downloads that i paid for from itunes are not there and are asking for payment again. How do i get my music i have already paid for?

    i didnt back it up to icloud before hand as i didnt realise you had to to it with itunes too. I have now paid for itunes match and it is still not showing the music that i purchased. The apple id is the same as before

  • I want to ask for help on your apple tv, where I noticed that the language Arabic has been deleted from the dictionary after update

    I want to ask for help on your apple tv, where I noticed that the language Arabic has been deleted from the dictionary after update

    You can ask Apple to add this via
    http://www.apple.com/feedback

Maybe you are looking for