join in the query with the result of a single line

Hi all

I have two tables
create table item(item_id number primary key,
item_desc varchar2(200));

create table item_properties(item_id number references item(item_id),
property_name varchar2(20),
property_value varchar2(100));
I insert the following records
insert into items values(1,'CPU');
insert into item_properties values(1,'RAM','2gb');
insert into item_properties values(1,'PROCESSOR','2ghz');
insert into item_properties values(1,'HARDDISK','2ghz');
commit;
now I want a query that produces the following results
item_id      RAM      PROCESSOR         HARDDISK
1              2gb        2ghz              2TB
How to generate this result?
I create a query, but it generates several lines, instead I need a single line like above.
select i.item_id,p.property_value from items i , item_properties p
where i.item_id=p.item_id and i.item_id=1;
Kind thanks.

Published by: Maahjoor on May 7, 2013 12:22 AM
select i.item_id,
       max(decode(p.property_name,'RAM',p.property_value)) ram,
       max(decode(p.property_name,'PROCESSOR',p.property_value)) processor,
       max(decode(p.property_name,'HARDDISK',p.property_value)) hd
from items i , item_properties p
where i.item_id=p.item_id
and i.item_id=1
group by i.item_id;

Or pivot to 11g

with details as
(
select i.item_id,p.property_name,p.property_value
from item i , item_properties p
where i.item_id=p.item_id
and i.item_id=1
)
select *
from details
pivot
 (
   max(property_value) for property_name in ('RAM','PROCESSOR','HARDISK')
 );

Published by: JAC on May 7, 2013 13:04

Tags: Database

Similar Questions

  • How to get the result of a single line in several columns

    I have a scenario where I asked five different columns in a table and it would still look back one line.

    So, for example: the query would be
     Select user1, user2, user3, user4 from table1 where tblkey= 2 
    So, this would mean 1 row with the value of their respective areas.

    In my code, I have a common function I can call to send an email to the list of people (User1, User2, user3, user4).

    So rather than call this function each time for each user, is there a way I can display the output to 4 different rows and use the loop For to call this function only once.

    In this way, the loop For running 4 times (if not nulls for all users) and call this function of e-mail.

    Really, I'd appreciate if someone could give me an idea of this scenario.

    Thank you
    AR

    If the number of columns is fixed you may be able to use this:

    SELECT  DECODE
            (
                    RN
            ,       1,USER1
            ,       2,USER2
            ,       3,USER3
            ,       4,USER4
            )       AS USERS
    FROM    TABLE1
    CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
    WHERE   TBLKEY = 2
    

    This UN-pivot results.

    Here's an example of it in action:

    SQL> CREATE TABLE TABLE1
      2  (
      3          TBLKEY  NUMBER
      4  ,       USER1   VARCHAR2(1)
      5  ,       USER2   VARCHAR2(1)
      6  ,       USER3   VARCHAR2(1)
      7  ,       USER4   VARCHAR2(1)
      8  );
    
    Table created.
    
    SQL> INSERT INTO TABLE1
      2  SELECT  ROWNUM
      3  ,       SUBSTR(OBJECT_NAME,1,1)
      4  ,       SUBSTR(OBJECT_NAME,2,1)
      5  ,       SUBSTR(OBJECT_NAME,3,1)
      6  ,       SUBSTR(OBJECT_NAME,4,1)
      7  FROM    ALL_OBJECTS
      8  WHERE ROWNUM <= 10;
    
    10 rows created.
    
    SQL> SELECT * FROM TABLE1 WHERE TBLKEY = 2;
    
                  TBLKEY USER1      USER2      USER3      USER4
    -------------------- ---------- ---------- ---------- ----------
                       2 I          _          U          S
    
    SQL> SELECT  DECODE
      2          (
      3                  RN
      4          ,       1,USER1
      5          ,       2,USER2
      6          ,       3,USER3
      7          ,       4,USER4
      8          )       AS USERS
      9  FROM    TABLE1
     10  CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
     11  WHERE   TBLKEY = 2
     12  /
    
    USERS
    -------------------------
    I
    _
    U
    S
    

    HTH!

    Published by: Centinul on February 24, 2010 11:21

  • I fill out an application online for the school. Is it possible to configure Firefox to check the spelling in a single-line text box without having to right click each time?

    I want to be able to set the spell checker to occur automatically, even for single-line text boxes.

    You can set the pref layout.spellcheckDefault to 2 on the topic: config page to perform spell checking on line and unique multi line text fields.

    To open the topic: config page, type Subject: config in the address bar (address) and press the 'Enter' key, as you type the url of a Web site to open a Web site.

    If you see a warning then you can confirm that you want to access this page.

    • Use the filter at the top bar of the on: page config to more easily spot a preference.
    • Preferences that have changed see the bold (user set).
    • Preferences you can restore the default value or change via the context menu.
  • Add the elements of a single line/column of a matrix

    Hi all

    What is the best way to add all the elements of a single row or column of a given matrix the matrix and the number of this line/column on LabVIEW? The output should be a number for each row or column.

    ARIJ,

    You always said not if you use a table or a matrix.

    The transposition has to be out of the loop.

    This will give you the sum of all rows and all columns.

    These are functions and LabVIEW base constructions. If you do not understand the concepts, please visit the online tutorials.

    Lynn

  • Several data merge the results on a single page

    Hello everyone,

    I'm currently developing menus for my upcoming wedding, where everyone has already chosen what they are experiencing.  I created a file .csv with four columns - name, Starter, main, Dessert.

    I print these at home, I want them to be half (105 x 297 mm) A4 format, with two menus per page.

    However, by the normal data merge, I end up with having the same menu twice on each page.  So two menus on the page are the same person.

    How do I set up so that I can have two different menus, the following entries in the file .csv, on the same page?

    Thanks in advance.

    Simon

    Looks like you tried to put both menus on the page and perform a merge of several record.

    To merge multiple records using only one set of placeholders on your page. Put it in the upper-left position. ID it dupliquera timeas as much as can fit in using the spacing settings you specify. It is often useful to use an empty block with no feature to define the area to perform the adjustment of the easier sapcing. Group them with your text, image (s).

  • The display of a single line to multiple columns

    Hello Oracle gurus,
    I am fairly new to the SQL development and hope that someone could help me

    I have an ID that repeated several times in 3 different tables based on a condition

    For your convenience, you can go

    Select a.id,
    B.SID,
    case when b.state = 1 then 'K' another thing ' n end.
    case when c.city = 2 then 'K' another thing ' n end
    PRIM one
    outer join STATE b left on a.id = b.id
    outer join CITY c left on a.id = c.id

    Results

    ID NAME STATE CITY
    1 Peter K N
    1 Peter N K
    Stewie 2 K N
    2 Stewie N K

    An additional line is coming because of Peter, his State Y and Y for the city.
    Expected results
    ID NAME STATE CITY
    1 Peter K K
    Stewie 2 N N


    How can I achieve this? I think I can do a union. but my actual query made 140 columns. so, I'm curious to know if there is another way to address the issue?
    Is it possible to use separate?
    Thanks in advance.

    What about

    select
     a.elig_id,
     max(case when b.part_supp_id= 2 then 'Y' else 'N' end) as A,
     max(case when b.part_supp_id=21 then 'Y' else 'N' end) as B
    from
      Elig_Test a
     ,Elig_Suppr b
    where
     a.elig_id=b.object_id
    group by
    a.elig_id
    
  • How to get the values in a single line, without the help of the union

    Hello

    I have a table with the structure and the following data

    EmpID address phoneno emailid
    1001 xyz
    1001 1234234
    1001 [email protected]
    1002 23434
    1002 [email protected]
    1003 abcd
    1003 [email protected]
    1004 [email protected]



    I need to get a result in this format.


    EMP id address phoneno emailid
    1001 xyz 1234234 [email protected]
    1002 23434 [email protected]
    1003 abcd [email protected]
    1004 [email protected]


    I can do this by using the union, but who gives a performance of questions with a large table. I want to do it using any other way using lead or something, but with the relative to data complexity, I couldn't do it.

    Can someone help me please?


    Natarajan

    Published by: Nikita on December 3, 2009 15:50
    Select employee_id, max(address), max(phone), max(email)
    from emp
    group by employee_id;
    

    Max

  • selection menu/popup/back of the box to a single line

    I am trying to program a control that allows the user to choose among 7 different options. The options are each other and collectively exhaustible (in other words, one must be selected at all times). I tried a menu box that begins with a single visible line (the line that contains the currently selected choice). Is that I wish it works: - when the user clicks on the box, all of the 7 choices appear - the movements of the user the cursor on the desired selection and releases (or clicks; I don't like) - the new selection 'takes' - the box comes back to the display of line one, I have the first part of work, but I can't find the right event (s) to do the rest. I'm on the right track? Suggestions to make this work? Thank you.

    I agree that any type of control of the ring is a good choice, an appropriate event is EVENT_VAL_CHANGED.

    But I also remind you that the CVI comes with a large collection of examples of programs, some of them also include controls of the ring. Analyze these samples can also familiarize themselves with CVI.

  • replace the carriage return, displaying the output on a single line

    [oracle@ccoshs02xvdbs01 ~] $ sqlplus deploy_ctl/deploy_ctl

    SQL * more: Production version 11.2.0.1.0 on Mon Mar 28 10:21:05 2011

    Copyright (c) 1982, 2009, Oracle. All rights reserved.


    Connected to:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options


    Modified session.

    10:21:05 SQL > insert into test (b) values ("this is stop
    10:21:38 2 space are now ');

    1 line of creation.

    10:21:47 SQL > commit;

    Validation complete.

    10:21:49 SQL > select test b where b as "this % ';

    B
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:22:07 SQL > select replace (b, chr (13)) of the test where b as "this % ';

    REPLACE (B, CHR (13))
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:22:56 SQL > select replace (b, chr (13), chr (32)) test fix where b as "this % ';

    DIFFICULTY
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    It is stop
    space wear now


    10:24:19 SQL >


    I would lilke to display on the same line.

    Thank you.

    Hello

    SQL> select translate(b,chr(13)||chr(10),chr(32)) fix from test where b like 'this%';
    
    FIX
    ----------------------------------------------------------------------------------------------------
    this is stopspace now carry on
    
    SQL> select translate(b,chr(13)||chr(10),' ') fix from test where b like 'this%';
    
    FIX
    ----------------------------------------------------------------------------------------------------
    this is stopspace now carry on
    

    -Pavan Kumar N

  • Join between the tables with Order By

    Hello

    Sorry if my question has already been postponed. I Googled, but I can't find any solution.

    This is the version of my DB: database Oracle 10 g Enterprise Edition Release 10.2.0.3.0.

    I created 3 tables. They contain up to 4000 lines.

    When I join without the order of closed I got a very quick response (less than 1 second), when I simply add Order By it gets more than 30 seconds!

    The order is on a Date field from the first table.

    Here's my query:

    Select *.

    tableOne tone

    two tableTwo full outer join on tone.message_id = ttwo.message_id

    outer join complete tableThree on two.field_id = tthree.field_id

    tone.ts desc order;

    I have some difficulties to export the plan to explain it...

    Should I create any clue? where? on the orders of field? on the join field?

    Any tips? Thank you.

    NO, it would not be

    Oracle does not work like that.

    ORDER BY is always, really always done LAST.

    ALWAYS.

    The second statement is a JOIN EXTERNAL LEFT and not a FULL OUTER JOIN, so the results will be different.

    Why "assume you' yours 'assumptions' are always right?

    They are not. You were probably in your dipers when I was already performance in Oracle 6.0.33

    --------------

    Sybrand Bakker

    Senior Oracle DBA

  • How to display the results of a MySql query in multiple columns?

    Hi, I know how to display PHP/MySq

    l of the results in a single column, but I'm really stuck to show

    Ying the results of several columns in DW CS4.

    Can someone help me with a code example? I'm new to php/mysql. Thank you

    Are you asking how to rotate the query results? Do a search for a horizontal loop. If this isn't what you're asking, please provide more details.

  • Divide the result from a query

    Hello

    I want to split/Group (I'm not sure about terms) a result of the query. Suppose I get a query with 50 results. I would like to show only 4 then the next 4 etc.. I have the following code that displays arrows active and inactive.
    I imagine the create a loop around my results of the 4 games and place each of these sets in a DIV. Images of related arrow would then show hide resp. the DIVs.

    The code below, I've prepared this day but I can't continue because can not resolve the above question and then find an effective idea of showing each result set.

    Someone has a good entry? It would be great!

    Thank you very much

    Here is the solution to my problem:
    http://www.Adobe.com/cfusion/webforums/Forum/MessageView.cfm?CATID=3&ThreadId=1402501

  • Report with the query with union and parameters

    Hello

    We have an obligation to create a report with the request, which is the union and parameters.

    I intend to create a database for the report based on a query. But the problem here is that the way to pass parameters in the query.

    Request is something like that

    Select x.a, x.b, x.c
    x
    where x.year =: para1
    and x.status = 'A '.
    Union of all the
    Select x.a, x.b, x.c
    x
    where x.year =: para1 - 1
    and (x.status = 'c' and x.date =: para2 or x.status = 'I' and x.date < =: para2)

    Here x.year in the first select statement must be equal to: para1 and second select statement, it should be: para - 1.

    How this requirement can be achieved?

    Client don't want to separate worksheet, a parameter and another for the actual data that I tried with sys_context and it worked. But the client wants the result in a single sheet only... So I need to change their approach.

    Help, please.

    Thank you

    Hello
    Another option is to convert the request so that you will have the items from the selection
    for example on the query you provided that you can use:

    Select 'Curr' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
    x
    where x.status = "A".
    Union of all the
    Select 'Prev' rec_type, x.a, x.b, x.c, x.year, x.date, x.status
    x
    where x.status in ('c', 'I')

    then, in the workbook, you will be able to create conditions such as:
    rec_type = 'Curr' and year =: para1

    rec_type = 'Prev' and year =: para1-1
    rec_type = 'Prev' and (status = 'c' and date =: para2 or status = 'I' and date)<=>

    Tamir

  • Confusion in the result...

    Oracle 10g version

    Hi gurus

    I have the sample data.

    Examples of data

    as with a reference
    (
    Select 'AAA' crt_file, 'A1' scode of union double all the
    Select 'AAA' crt_file, 'A2' from dual union all
    Select "AAA" crt_file, null of union double all the
    Select 'BBB' crt_file, 'A1' scode of union double all the
    Select 'BBB' crt_file, 'A2' from dual union all
    Select 'BBB' crt_file, the double null

    )
    Select * reference
    where crt_file = "AAA".
    (scode = & s_cd
    Gold 1 = 1
    );

    When I 'A1' and then it will show all the result against AAA, but I think he should return only 1 row which is 'A1' not all the lines for crt_file = YYYY.

    Please advice

    Concerning

    Matt

    Hello

    Matt. wrote:

    Hi Frank

    Sorry to bother you again, you said.

    If p is true, then there is no need to evaluate q.  If p evaluates to false or Unknown, q must be evaluated.

    Anyway

    In my case it's the same when I pass the parameter 'A1' then left condition site do not TRUE so no need to assess 1 = 1 condition and then the result should be stored not all one line... Please suggest

    When you pass the parameter 'A1', then sometimes the left side of the condition-GOLD, it's TRUE and on these lines there is no need to evaluate the right.side.

    When you pass the parameter 'A1', then sometimes the left side of the OR condition is FALSE or UNKNOWN and on these lines it is necessary to assess the right.side

    Whatever either, or the condition there the TRUE value...

    As stew said in response to #9, the WHERE clause is evaluated for each row.  The results you get from a line do not affect the results you get on another line.  That's the whole point of a WHERE clause, is not?  In general, you want something that will be TRUE for some lines, but not for the other lines.

    When you pass 'A1' as a parameter, you say that you expect the results to include 'all lines', but I think it's fair to say "all lines containing ="AAA"crt_file", as you said in your original message.  The condition

    crt_file = "AAA".

    must be evaluated on each row independently the other lines.  It is the same for all rows in the table.

    When it's time to decide whether to include this line:

    Select 'AAA' crt_file, 'A2' from dual union all

    so, if & s_code = 'A1', the line will be included.  Why?  First of all, the condition on the left side of the AND, which is

    crt_file = "AAA".

    is evaluated.  This State is set to TRUE for this line, so it is necessary to evaluate the right side of the AND, which is itself a condition GOLD-composed.  The left side of the GOLD, it's

    SCODE = & s_cd

    is evaluated, and it turns out to be FAKE for that line, so the right side of the GOLD, it's

    1 = 1

    is evaluated, and which proves to be TRUE, then, on this line, WHERE any condition, i.e.

    crt_file = "AAA".

    (scode = & s_cd
    Gold 1 = 1
    )

    takes the value

    TRUE

    and (FAKE

    or TRUE

    )

    that is the same

    TRUE

    and ago (REAL

    )

    that is the same

    TRUE

    How this condition was assessed on the first line has no impact on how it will assess on other lines.  (And even if it did, how do you know what the first line?  Rows in a table have no built-in command.  If you run the same query over and over, different lines can be read first every time.)

  • How to merge data from the table with a single line

    Hello

    I have three tables subscription_type, the address and the person. Here are the details of the table

    Person Subscription_type Address                                           

    Person_Id AdressType_id Address_id

    Person_name Description Address_type_id

    Person_id

    Address details


    There are three types of different address - home, postal and previous.

    Each person can have these three different addresses.

    I want to create a view that displays all addresses of three of each person in the table of the person in a single line.

    Any help please

    In your example, there are 2 rows of columns street1, TOWN, SUBURB etc for a single person. To convert this into a single line, with the new columns we could simply use CASES or DECODE in the select as the SQL below. To understand why consolidation function THAT MAX is used - remove the MAX and GROUP BY in SQL keyword and try.

    Select full_name

    , max (case when description = "Home" then end street1) Home_Street

    , max (case when description = "Home" then end suburb) home_suburb

    , max (case when description = end of the "Home" then City) home_city

    , max (case when description = "Home" then postal code end) home_postcode

    , max (case when description = "Home" then end state_name) home_state

    , max (case when description = 'Postal' then end street1) Postal_Street

    , max (case when description = 'Postal' and then end of suburb) Postal_suburb

    , max (case when description = 'Postal' then the city) Postal_city

    , max (case when description = 'Postal' and then end of CP) Postal_postcode

    , max (case when description = 'Postal' then state_name end) Postal_state

    , max (case when description = "Back" then end street1) Prev_Street

    , max (case when description = "Back" then end suburb) Prev_suburb

    , max (case when description = "Back" then city end) Prev_city

    , max (case when description = "Back" then postal code end) Prev_postcode

    address a

    S State

    No p

    Subscription_type att

    where a.person_id = p.person_id

    and a.state_id = s.state_id

    and a.address_type_id = att.address_type_id

    Full_name group

Maybe you are looking for