How can i join this two query?

I have two table table employee and CSEReduxResponses
In table employee i have
CREATE TABLE [dbo].[employee](
[emp_id] [int] IDENTITY(1,1) NOT NULL,
[emp_namefirst] [varchar](255) NOT NULL,
[emp_namemiddle] [varchar](50) NULL,
[emp_namelast] [varchar](255) NOT NULL
on responds i have 
CREATE TABLE [dbo].[CSEReduxResponses](
[response_id] [int] IDENTITY(1,1) NOT NULL,
[employee] [int] NOT NULL,
[employeedept] [int] NOT NULL,
[star] [tinyint] NOT NULL,
[status] [int] NOT NULL,
[approvedby] [int] NULL,
[approveddate] [datetime] NULL,
[execoffice_status] [int] NULL,
Im trying to get the employee with the MAX execpffice_status( this is either a 1 or 0).
i have this query that i made for it
select top(1) with ties employee, SUM(execoffice_status) as 'total'
from   CSEReduxResponses
group by employee
order by 'total' desc
my query for employee table is 
   select emp_namefirst as first , emp_namelast as [last]
from phonelist.dbo.employee where emp_namefirst is not null
How can i get this 2 query together so i can output the employee (first and last )name
with the max exeoffice_status?
i use :
Microsoft SQL Server Management Studio 10.0.2531.0
ps: sorry if i put this is the wrong forum, this is my first time here and first post.

Are you looking for the below?
CREATE TABLE [dbo].[employee](
[emp_id] [int] IDENTITY(1,1) NOT NULL,
[emp_namefirst] [varchar](255) NOT NULL,
[emp_namemiddle] [varchar](50) NULL,
[emp_namelast] [varchar](255) NOT NULL
Insert into Employee Values('abc','bcd','cdf')
Insert into Employee Values('xyz','yxw','xwv')
CREATE TABLE [dbo].[CSEReduxResponses](
[response_id] [int] IDENTITY(1,1) NOT NULL,
[employee] [int] NOT NULL,
[employeedept] [int] NOT NULL,
[star] [tinyint] NOT NULL,
[status] [int] NOT NULL,
[approvedby] [int] NULL,
[approveddate] [datetime] NULL,
[execoffice_status] [int] NULL,
Insert into [CSEReduxResponses]( employee,employeedept,star,status,approvedby,approveddate,execoffice_status)
Values(1,100,1,1,1,GETDATE(),0),
(1,100,1,1,1,GETDATE(),1),
(2,100,1,1,1,GETDATE(),0)
;With cte as( Select *,SUM([execoffice_status]) over(partition by Employee) sumstatus From [CSEReduxResponses] )
Select Distinct A.*,B.sumstatus
From Employee A
Inner Join cte B On A.emp_id = B.employee
--OR
;With cte as( Select employee ,SUM([execoffice_status]) sumstatus From [CSEReduxResponses] group by Employee)
Select Distinct A.*,(Select sumstatus From cte B where A.emp_id = B.employee)
From Employee A
Drop table Employee,[CSEReduxResponses]

Similar Messages

  • How can I make this complex query?

    I don’t know how can I do this complex query...
    I have the tables Customers, Vehicles and Models. A customer can have 0-N Vehicles and a vehicle have 1 Model.
    Customers: ID_Customer (PK), Name, LastName...
    Vehicles: ID_Vehicle (PK), ID_Customer, ID_Model, date_sale
    Models: ID_Modelo (PK), Model_Name
    Then I need to know the buy average time (date_sale) between 2 models (ID_Model)
    For example I have these Vehicles:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    If I want to know the buy average time (date_sale) between ID_Model 1 and ID_Model 2 it is. (403 + 467) / 2 = 435 days !!!
    * Customer 123 (model 1 to 2): 25/06/2001 – 21/05/2000 ==> 403 days
    * Customer 516 (model 1 to 2): 01/12/2002 – 01/05/2000 ==> 467 days.
    I need to do the query for all the combination models. For example If I have the Models 1, 2 and 3 I need to obtain:
    Source_Model.....Target_Model....Buy_Average_Time
    1......................................1....................... xxx days
    1......................................2....................... xxx days
    1......................................3....................... xxx days
    2......................................1....................... xxx days
    2......................................2....................... xxx days
    2......................................3....................... xxx days
    3......................................1....................... xxx days
    3......................................2....................... xxx days
    3......................................3....................... xxx days
    If it is necessary I could create a table with the fields Source_Model, Target_Model and Buy_Average_Time for accelerate the query time response.
    But how can I do this query??????????
    Thanks very much!!!

    Hi,
    Thanks for your reply but It is not correct for me because the Customer could have several vehicles in her life.
    If I make the query with my examples data it is OK
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    1................................123....................1.............21/05/2000
    2................................459....................3............ 16/08/2000
    3................................123....................2............ 28/06/2001
    4................................516....................1............ 09/09/2001
    5................................459....................4............ 18/10/2002
    6................................516....................2............ 20/12/2002
    select v1.id_model as source_model,
    v2.id_model as target_model,
    avg (v2.date_sale - v1.date_sale) || ' days' as buy_average_time
    from vehicles v1,
    vehicles v2
    where v1.id_customer = v2.id_customer
    and v2.date_sale > v1.date_sale
    group by v1.id_model, v2.id_model;
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2.....................................435 days
    ..............3................................4.....................................793 days
    But If I insert a new vehicle:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................3............ 16/08/2003
    And I execute the query now I receive:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................435 days
    ..............1................................3...........................706 days
    ..............2................................3...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because I don’t have the 1 (Source_model) to 3 (Target_model) combination in the Vehicles data!!! (I have 1 to 2 and 2 to 3 but NO 1 to 3!!!!).
    Then the query is not OK for me!
    Besides If I modify the Vehicle 7 data and put ID_Model = 2:
    ID_Vehicle (PK)...ID_Customer...ID_Model....date_sale
    7................................516....................2............ 16/08/2003
    I received:
    SOURCE_MODEL     TARGET_MODEL     BUY_AVERAGE_TIME
    ..............1................................2...........................525,33 days
    ..............2................................2...........................239 days
    ..............3................................4...........................793 days
    It is NO correct because the BUY_AVERAGE_TIME for 1 to 2 combination is 435 days (the same of the original query) because I aggregate only the combination 2 to 2 with the ID_VEHICLE 7
    Below I attach the examples scripts.
    Could you help me with this query, please?
    Thanks very much!
    CREATE TABLE VEHICLES
    ID_VEHICLE NUMBER(9),
    ID_CUSTOMER NUMBER(9),
    ID_MODEL NUMBER(9),
    DATE_SALE DATE
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    1, 123, 1, TO_Date( '05/21/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    2, 459, 3, TO_Date( '08/16/2000 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    3, 123, 2, TO_Date( '06/28/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    4, 516, 1, TO_Date( '09/09/2001 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    5, 459, 4, TO_Date( '10/18/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    6, 516, 2, TO_Date( '12/20/2002 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    INSERT INTO VEHICLES ( ID_VEHICLE, ID_CUSTOMER, ID_MODEL, DATE_SALE ) VALUES (
    7, 516, 2, TO_Date( '08/16/2003 12:00:00 AM', 'MM/DD/YYYY HH:MI:SS AM'));
    COMMIT;
    CREATE TABLE MODELS
    ID_MODELO NUMBER(9),
    MODEL_NAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    1, 'MODEL 1');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    2, 'MODEL 2');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    3, 'MODEL 3');
    INSERT INTO MODELS ( ID_MODELO, MODEL_NAME ) VALUES (
    4, 'MODEL 4');
    COMMIT;
    CREATE TABLE CUSTOMERS
    ID_CUSTOMER NUMBER(9),
    NAME VARCHAR2(25 BYTE),
    LASTNAME VARCHAR2(25 BYTE)
    TABLESPACE USERS
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    123, 'Customer 123', 'A');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    459, 'Customer 459', 'B');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    516, 'Customer 516', 'C');
    INSERT INTO CUSTOMERS ( ID_CUSTOMER, NAME, LASTNAME ) VALUES (
    318, 'Customer 318', 'D');
    COMMIT;

  • How to join this two query

    Hi all,
    i have these two query .
    SELECT A.DATENUM,A.ATT_STATE,B.OT_MINUTES FROM WEB_HR.HR_ATTENDANCE A,WEB_HR.HR_OVERTIME B
              WHERE A.MONTH_ID=2 AND A.ATT_YEAR=2009 AND A.EMP_ID=1 AND A.EMP_ID=B.EMP_ID
              AND A.COMPANYCODE=1 AND A.DATENUM<=16 ORDER BY a.DATENUM;
              SELECT A.DATENUM AS VDATENUM,A.ATT_STATE AS VATT_STATE,B.OT_MINUTES AS VOT_MINUTES FROM WEB_HR.HR_ATTENDANCE A,WEB_HR.HR_OVERTIME B
              WHERE A.MONTH_ID=2 AND A.ATT_YEAR=2009 AND A.EMP_ID=1 AND A.EMP_ID=B.EMP_ID
              AND A.COMPANYCODE=1 AND A.DATENUM >16 ORDER BY a.DATENUM;
    actually from these two query each query returning 3 column each .
    so what i need is i want mearge these two in such way that it return 6 column at a time..
    can i get this??

    You can do that by just joining them. Let's assume your two queries are Q1 and Q2, both with columns c1-3, then just:
    select q1.c1, q1.c2, q1.c3, q2.c1, q2.c2, q2.c3
    from (Q1) q1
        ,(Q2) q2But this will result in a cartesian product of the two resultsets (from Q1 and Q2).
    The big question is how do you want to combine the rows that come out of Q1 with the rows that come out of Q2. For instance if DATENUM is unique in both resultsets, and you want to combine rows that have matching values on DATENUM (c1, below), then:
    select q1.c1, q1.c2, q1.c3, q2.c1, q2.c2, q2.c3
    from (Q1) q1
        ,(Q2) q2
    where q1.c1 = q2.c1Toon

  • How Can I Make This Sql Query To Load Data Correctly (sql server)?

    Hi guys
    I have a datagridview where the third column is a custom column with all days
    of a month. It takes data with a query who distinct the column Improve.
    Here is the code :
    Private Sub fill_impro()
    dgImprove.Rows.Clear()
    Try
    Dim i As Integer = 0
    Dim query As String = "SELECT Improve,Price,Active,Idate FROM (SELECT Improve,Price,Active,Idate, ROW_NUMBER() OVER (PARTITION BY Price ORDER BY Price) AS rn FROM tblImprove) tmp WHERE rn = 1"
    cmd = New SqlCommand(query, clsMSSQL.con)
    myDR = cmd.ExecuteReader
    If myDR.HasRows Then
    While myDR.Read
    dgImprove.Rows.Add()
    dgImprove.Rows(i).Cells(0).Value = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    dgImprove.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Improve"))
    Dim myday As Integer = DatePart(DateInterval.Day, myDR.GetValue(myDR.GetOrdinal("Idate")))
    dgImprove.Rows(i).Cells(myday + 1).Value = myDR.GetInt32(myDR.GetOrdinal("Active"))
    i = i + 1
    End While
    End If
    myDR.Close()
    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Critical, "Σφάλμα")
    End Try
    End Sub
    And here is the result :
    http://i60.tinypic.com/28gwf83.jpg
    The column Active value is 1.
    The problem is that column Active values are missing (red values in image).
    How can i fix that ?
    Thanks in advance

    try like this
    Dim Price As Decimal
    Dim improve As String = String.Empty
    While myDR.Read
    Dim myday As Integer = DatePart(DateInterval.Day, myDR.GetValue(myDR.GetOrdinal("Idate")))
    If Not (myDR.GetDecimal(myDR.GetOrdinal("Price")) = Price And myDR.GetString(myDR.GetOrdinal("Improve")) = improve) Then
    i += 1
    dgimprove.Rows.Add()
    dgimprove.Rows(i).Cells(0).Value = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    dgimprove.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Improve"))
    Price = myDR.GetDecimal(myDR.GetOrdinal("Price"))
    improve = myDR.GetString(myDR.GetOrdinal("Improve"))
    End If
    dgimprove.Rows(i).Cells(myday + 1).Value = myDR.GetInt32(myDR.GetOrdinal("Active"))
    End While
    and change your sql statement to just
    SELECT Improve,Price,Active,Idate FROM tblImprove WHERE Active = 1

  • How Can I Make This Sql Query To Load Data Correctly (sql server 2014)?

    Hi guys
    I have a datagridview where the third column is a custom column with all days
    of a month. It takes data with a query who distinct the column Improve.
    SELECT Improve,Price,Active,Idate FROM (SELECT Improve,Price,Active,Idate, ROW_NUMBER() OVER (PARTITION BY Improve ORDER BY Improve) AS rn FROM tblImprove) tmp WHERE rn = 1
    And here is the result :
    http://i60.tinypic.com/28gwf83.jpg
    The column Active value is 1.
    The problem is that column Active values are missing (red values in image).
    How can i fix that ?
    Thanks in advance
     

    Hi, 
    Maybe you can try below code, I have changed the order by of the row_number(). Therefore it will sort on the date, and you will get the first date icm with improve cell. If this is not what you are looking for, please explain what the output should be. 
    SELECT Improve,Price,Active,Idate
    FROM
    SELECT Improve,Price,Active,Idate, ROW_NUMBER() OVER (PARTITION BY Improve ORDER BY ldate) AS rn
    FROM tblImprove
    ) tmp WHERE rn = 1
    Regards, 
    Reshma
    Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered

  • How can i do this two figures? semicircles on circle...

    look the image, how to create it? if i want 16 semicircle over a circle what i have to do? can't find a solution on myself.
    and if want it on a square?
    thank you
    [URL=http://imageshack.us/photo/my-images/15/tttmb.jpg/][IMG]http://img15.imageshack.us/img15/6715/tttmb.jpg[/IMG][/URL]

    Tr4y this it might be simpler in some ways
    I made a rectangle and gave it a stroke in this case 30mm
    then I made that a dash use round caps a 0 dash and 29mm gap
    Then I outline the stroke
    Gve the resulting art a fill of none and a stroke of 1mm
    Then I used the Unite Coommand on the Pathfinder
    Then I deleted the the interior element and go this.
    As far as an exact number that is a matter of math the relationship of the wieght of the stroke to the size of the rectangle or Ellipse.

  • How can I perform this kind of range join query using DPL?

    How can I perform this kind of range join query using DPL?
    SELECT * from t where 1<=t.a<=2 and 3<=t.b<=5
    In this pdf : http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,
    It shows how to perform "Two equality-conditions query on a single primary database" just like SELECT * FROM tab WHERE col1 = A AND col2 = B using entity join class, but it does not give a solution about the range join query.

    I'm sorry, I think I've misled you. I suggested that you perform two queries and then take the intersection of the results. You could do this, but the solution to your query is much simpler. I'll correct my previous message.
    Your query is very simple to implement. You should perform the first part of query to get a cursor on the index for 'a' for the "1<=t.a<=2" part. Then simply iterate over that cursor, and process the entities where the "3<=t.b<=5" expression is true. You don't need a second index (on 'b') or another cursor.
    This is called "filtering" because you're iterating through entities that you obtain from one index, and selecting some entities for processing and discarding others. The white paper you mentioned has an example of filtering in combination with the use of an index.
    An alternative is to reverse the procedure above: use the index for 'b' to get a cursor for the "3<=t.b<=5" part of the query, then iterate and filter the results based on the "1<=t.a<=2" expression.
    If you're concerned about efficiency, you can choose the index (i.e., choose which of these two alternatives to implement) based on which part of the query you believe will return the smallest number of results. The less entities read, the faster the query.
    Contrary to what I said earlier, taking the intersection of two queries that are ANDed doesn't make sense -- filtering is the better solution. However, taking the union of two queries does make sense, when the queries are ORed. Sorry for the confusion.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How can I make this join in ADF and make CRUD operation in this

    How to make this relation in ADF
    I have table employees and this is my master table
    Table Name: Employees
    Columns:
    Employee_id(PK)
    Employee_name
    Employee_Salary
    I have a child table that is called related employee that contains employees related to this employee
    Table_name: Related_Employee
    Columns:
    Related_Employee_Table_Id(PK)
    Employee_id(FK)
    Related_Employee_Id
    When I open employee id = 100 for example and add related employee id = 10
    this is added with no problem but the requirement is that when I open employee 10 I find employee id 100 as related employee
    How can I make this scenario.

    The best way to understand this is to look at an example. If you are using an oracle database such as XE for you have a schema called hr. This shema has a number of tables two of which are departments and employees. a department has multiple employees correct. So in your example a employee may be related to x # of other employees perhaps. A very similar scenario as that in the hr Schema. If you don't have an Oracle XE database, download one from here -> http://www.oracle.com/technetwork/database/express-edition/downloads/index.html
    Create Business Components off of the Departments and Employees schema and you'll see that due to the db design, you get what you're talking about for free (i.e. the join). Thus, you have the master-detail relationship you're looking for. For a quick tip, here is the relationship between departments and employees in the hr schema via a create script that you can exam with data inserts included:
    SET SQLBLANKLINES ON
    CREATE TABLE DEPARTMENTS
    DEPARTMENT_ID NUMBER(4, 0) NOT NULL
    , DEPARTMENT_NAME VARCHAR2(30 BYTE) NOT NULL
    , MANAGER_ID NUMBER(6, 0)
    , LOCATION_ID NUMBER(4, 0)
    , CONSTRAINT DEPT_ID_PK PRIMARY KEY
    DEPARTMENT_ID
    USING INDEX
    CREATE UNIQUE INDEX DEPT_ID_PK ON DEPARTMENTS (DEPARTMENT_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 1
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE TABLE EMPLOYEES
    EMPLOYEE_ID NUMBER(6, 0) NOT NULL
    , FIRST_NAME VARCHAR2(20 BYTE)
    , LAST_NAME VARCHAR2(25 BYTE) NOT NULL
    , EMAIL VARCHAR2(25 BYTE) NOT NULL
    , PHONE_NUMBER VARCHAR2(20 BYTE)
    , HIRE_DATE DATE NOT NULL
    , JOB_ID VARCHAR2(10 BYTE) NOT NULL
    , SALARY NUMBER(8, 2)
    , COMMISSION_PCT NUMBER(2, 2)
    , MANAGER_ID NUMBER(6, 0)
    , DEPARTMENT_ID NUMBER(4, 0)
    , CONSTRAINT EMP_EMP_ID_PK PRIMARY KEY
    EMPLOYEE_ID
    USING INDEX
    CREATE UNIQUE INDEX EMP_EMP_ID_PK ON EMPLOYEES (EMPLOYEE_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 1
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX DEPT_LOCATION_IX ON DEPARTMENTS (LOCATION_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_DEPARTMENT_IX ON EMPLOYEES (DEPARTMENT_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_JOB_IX ON EMPLOYEES (JOB_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_MANAGER_IX ON EMPLOYEES (MANAGER_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_NAME_IX ON EMPLOYEES (LAST_NAME ASC, FIRST_NAME ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_EMAIL_UK UNIQUE
    EMAIL
    USING INDEX
    CREATE UNIQUE INDEX EMP_EMAIL_UK ON EMPLOYEES (EMAIL ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_LOC_FK FOREIGN KEY
    LOCATION_ID
    REFERENCES LOCATIONS
    LOCATION_ID
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_MGR_FK FOREIGN KEY
    MANAGER_ID
    REFERENCES EMPLOYEES
    EMPLOYEE_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_DEPT_FK FOREIGN KEY
    DEPARTMENT_ID
    REFERENCES DEPARTMENTS
    DEPARTMENT_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_JOB_FK FOREIGN KEY
    JOB_ID
    REFERENCES JOBS
    JOB_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_MANAGER_FK FOREIGN KEY
    MANAGER_ID
    REFERENCES EMPLOYEES
    EMPLOYEE_ID
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_NAME_NN CHECK
    (DEPARTMENT_NAME IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_EMAIL_NN CHECK
    (EMAIL IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_HIRE_DATE_NN CHECK
    (HIRE_DATE IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_JOB_NN CHECK
    (JOB_ID IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_LAST_NAME_NN CHECK
    (LAST_NAME IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_SALARY_MIN CHECK
    (SALARY > 0)
    ENABLE;
    COMMENT ON TABLE DEPARTMENTS IS 'Departments table that shows details of departments where employees
    work. Contains 27 rows; references with locations, employees, and job_history tables.';
    COMMENT ON TABLE EMPLOYEES IS 'employees table. Contains 107 rows. References with departments,
    jobs, job_history tables. Contains a self reference.';
    COMMENT ON COLUMN DEPARTMENTS.DEPARTMENT_ID IS 'Primary key column of departments table.';
    COMMENT ON COLUMN DEPARTMENTS.DEPARTMENT_NAME IS 'A not null column that shows name of a department. Administration,
    Marketing, Purchasing, Human Resources, Shipping, IT, Executive, Public
    Relations, Sales, Finance, and Accounting. ';
    COMMENT ON COLUMN DEPARTMENTS.MANAGER_ID IS 'Manager_id of a department. Foreign key to employee_id column of employees table. The manager_id column of the employee table references this column.';
    COMMENT ON COLUMN DEPARTMENTS.LOCATION_ID IS 'Location id where a department is located. Foreign key to location_id column of locations table.';
    COMMENT ON COLUMN EMPLOYEES.EMPLOYEE_ID IS 'Primary key of employees table.';
    COMMENT ON COLUMN EMPLOYEES.FIRST_NAME IS 'First name of the employee. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.LAST_NAME IS 'Last name of the employee. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.EMAIL IS 'Email id of the employee';
    COMMENT ON COLUMN EMPLOYEES.PHONE_NUMBER IS 'Phone number of the employee; includes country code and area code';
    COMMENT ON COLUMN EMPLOYEES.HIRE_DATE IS 'Date when the employee started on this job. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.JOB_ID IS 'Current job of the employee; foreign key to job_id column of the
    jobs table. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.SALARY IS 'Monthly salary of the employee. Must be greater
    than zero (enforced by constraint emp_salary_min)';
    COMMENT ON COLUMN EMPLOYEES.COMMISSION_PCT IS 'Commission percentage of the employee; Only employees in sales
    department elgible for commission percentage';
    COMMENT ON COLUMN EMPLOYEES.MANAGER_ID IS 'Manager id of the employee; has same domain as manager_id in
    departments table. Foreign key to employee_id column of employees table.
    (useful for reflexive joins and CONNECT BY query)';
    COMMENT ON COLUMN EMPLOYEES.DEPARTMENT_ID IS 'Department id where employee works; foreign key to department_id
    column of the departments table';

  • How can i improve this query.

    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .

    952936 wrote:
    Hi guys i am beginner , just wanted to know some info , how can i improve this query ..
    select *
    from tableA A, viewB B,
    where A.key = B.key
    and a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    one more thing should function should be on left side of equal sign.
    will a join make it better or something else is needed more than that .If you are a beginner try to learn the ANSI Syntax. This will help you a lot to write better queries.
    Your select would look like this in ANSI.
    select *
    from tableA A
    JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_function(a.key);The good thing here is that this separates the typical joining part of the select from the typical filter criteria.
    The other syntax very often let you forget one join. Just because there are so many tables and so many filters, that you just don't notice correctly anymore what was join and what not.
    If you notice that the number of column is not what you expect, you can easiely modify the query and compare the results.
    example A
    Remove View B from the query (temporarily comment it out).
    select *
    from tableA A
    --JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)
    example B
    You notice, that values from A are missing. Maybe because there is no matching key in ViewB? Then change the join to an outer join.
    select *
    from tableA A
    LEFT OUTER JOIN viewB B ON A.key = B.key
    WHERE a.criteria1 = '111'
    and a.criteria2 = some_funtion(a.key)(The outer keyword is optional, left join would be enough).

  • How can i join two libraries from two different users

    how can i join two libraries from two different users in the same computer?

    I should add that you can turn on SHARING where each user can see the other user's library and play stuff out of it. But they can not import those tracks to their own library or put them into their own playlists or burn CDs of the shared library.
    Also note, to do this you need to have the fast switching option enabled with the accounts so both can be running at the same time and both must have iTunes running at the same time.
    Patrick

  • How to join this two tables

    Hi
    have a two login in forms not in oracle... i have two tables first the
    Master secodn the Employees.. my prob is i have two button for this two tables to login.. any solution on how i can join this two in one button that if i connect using from master tables or from employess it will login
    FirstTAble:::
    BEGIN
    iF :username IS NULL THEN
    MESSAGE ('Please enter Username ');
    MESSAGE ('Please enter Username ');
    GO_ITEM('username');
    RAISE FORM_TRIGGER_FAILURE;
    end if;
    IF :PASSNAME1 IS NULL THEN
    MESSAGE('Please enter password.');
    MESSAGE('Please enter password.');
    GO_ITEM('PASSNAME1');
    RAISE FORM_TRIGGER_FAILURE;
    end if;
    select username,passname
    into :pass.username,:pass.passname1
    from Master
    where :pass.username=username
    and :pass.passname1=passname;
    Message('Access Granted');
    Message('Access Granted');
    go_block('maina');
    hide_view('pass1');
    exception
    when no_Data_found then
    set_alert_Property('wrong',Alert_Message_text,'Invalid Password');
    if show_alert('wrong')=alert_button1 then
              go_item('PASSNAME1');
              :passname1:=null;
              end if;
    end;
    SEcodnTAble
    BEGIN
    iF :username IS NULL THEN
    MESSAGE ('Please enter Username ');
    MESSAGE ('Please enter Username ');
    GO_ITEM('username');
    RAISE FORM_TRIGGER_FAILURE;
    end if;
    IF :PASSNAME1 IS NULL THEN
    MESSAGE('Please enter password.');
    MESSAGE('Please enter password.');
    GO_ITEM('PASSNAME1');
    RAISE FORM_TRIGGER_FAILURE;
    end if;
    select username,passname
    into :pass.username,:pass.passname1
    from Employees
    where :pass.username=username
    and :pass.passname1=passname;
    Message('Access Granted');
    Message('Access Granted');
    go_block('maina');
    hide_view('pass1');
    exception
    when no_Data_found then
    set_alert_Property('wrong',Alert_Message_text,'Invalid Password');
    if show_alert('wrong')=alert_button1 then
              go_item('PASSNAME1');
              :passname1:=null;
              end if;
    end;

    use a union on the 2 select statements.

  • HT201368 what if I have two different librarys located in different areas , one on OS another on External. How Do I Join Them Two One Massive libary, As Well As Add More Collections To It, Where Can I Also Setup For Industry M-Audio Axiom 61 3rd Gen Contr

    what if I have two different librarys located in different areas , one on OS another on External. How Do I Join Them Two One Massive libary, As Well As Add More Collections To It, Where Can I retain These Extra Librarys?  Also Setup For Industry M-Audio Axiom 61 3rd Gen Controler...?

    >
    <IfModule mod_weblogic.c>
    WebLogicCluster 127.0.0.1:7005,127.0.0.1:7007,127.0.0.1:7003,127.0.0.1:7103,127.0.0.1:7104
    MatchExpression /app1
    </IfModule>
    <Location /weblogic>
    SetHandler weblogic-handler
    WebLogicCluster 127.0.0.1:7003,127.0.0.1:7005,127.0.0.1:7007,127.0.0.1:7103,127.0.0.1:7104
    DebugConfigInfo ON
    PathTrim /weblogic
    </Location>
    <IfModule mod_weblogic.c>
    WebLogicCluster 127.0.0.1:7003,127.0.0.1:7005,127.0.0.1:7007
    MatchExpression /app2
    </IfModule>
    <Location /weblogic>
    SetHandler weblogic-handler
    WebLogicCluster 127.0.0.1:7003,127.0.0.1:7005,127.0.0.1:7007
    DebugConfigInfo ON
    PathTrim /weblogic
    </Location>
    >
    This configuration is weird little bit. There is MatchExpression /app1 and MatchExpression /app2 and at the same time two <Location /weblogic> sections. Are you sure you understand what that configuration stands for?
    Try something like this ...
    <Location /app1>
    SetHandler weblogic-handler
    WebLogicCluster 127.0.0.1:7003,127.0.0.1:7005,127.0.0.1:7007,127.0.0.1:7103,127.0.0.1:7104
    DebugConfigInfo ON
    </Location>
    <Location /app2>
    SetHandler weblogic-handler
    WebLogicCluster 127.0.0.1:7003,127.0.0.1:7005,127.0.0.1:7007
    DebugConfigInfo ON
    </Location>
    where /app1 and /app2 are contexts of your weblogic applications.
    http://download.oracle.com/docs/cd/E11035_01/wls100/plugins/apache.html
    http://httpd.apache.org/docs/2.0/mod/core.html#location

  • How can I share two differents Itunes accounts in my Apple TV ? I have one and my wife has another account and we want to share both in our apple tv. How can I do this ???

    How can I share two differents Itunes accounts in my Apple TV ? I have one and my wife has another account and we want to share both in our apple tv. How can I do this ???

    I assume you have different iTunes collections on different PC's, or on different logins on the same PC?  If that's the case then just enable "Home Sharing" in each iTunes using the SAME iTunes username and password as you enabled home sharing on the Apple TV with. The account used for home sharing is NOT the same as the account used to access the iTunes store, so as long as you use the same account (pick one, doesn't matter which) then you should see both of yor iTunes libraries on the Apple TV. Note - each iTunes has ti be running in order for the Apple TV to see the library.
    Here's some details on how to do it:
    http://support.apple.com/kb/HT4363

  • I own a 13-inch MacBook Pro and for the past day, my wifi on my laptop says I only have two bars of connection and is running very slow,but all of my other devices such as my iPhone and iPad are connecting perfectly to the wifi. How can I fix this? Thanks

    I own a 13-inch MacBook Pro and for the past day, my wifi on my laptop says I only have two bars of connection and is running very slow,but all of my other devices such as my iPhone and iPad are connecting perfectly to the wifi. How can I fix this? I have tried to shut my laptop off and let it rest and I have also re-started my wifi router three different times. Someone please help me with this problem so I can begin to use my laptop again as I take it to school and use it for class.
    Thanks so much!

    FCP, and all software on OSX, has a few different "preference" files (the extension is .plist), which store all your user settings. Each time you resize a window, change a setting, anything, this file is re-written. Kinda easy to see how they would become corrupt every now and then.
    -Close FCP
    -Navigate to User>Library>Preferences and delete com.apple.FinalCutPro.plist
    -Navigate to User>Library>Preferences>Final Cut Pro User Data and delete Final Cut Pro 5.0 Prefs
    -Empty your trash
    Relaunch FCP and see if that worked.
    Download FCP Rescue to make this process easier in the future. When you have FCP running really smooth, open FCP Rescue and create a backup of your preference files. If it starts acting wanky, just run FCP Rescue and Restore your backup preferences. Works really slick, and it's free.
    EDIT: Or use the really simple explaination that X posted as I was typing.

  • I have two different accounts with I-tunes and I want to link both purchases for my music to one account. How can I do this?

    I have two different accounts with I-tunes and I want to link both purchases for my music to one account. How can I do this?

    You are going to need to change the email address you use with your old ID. Once you have got access to your old account you will then log into both accounts at the same time on your Mac and transfer your data to a single account. We can do this later, but need you to get access to your old account first.
    My Apple ID

Maybe you are looking for