Select statement using 2 tables
Hi Experts,
In the following code, i have to select "v_likp-charg" into the "concatenate" statement.
could you please let me know, how can i do that.
help is appreciated,
code:
<b>data: i_kna1 type t_kna1 occurs 0,
v_kna1 type t_kna1,
i_likp type t_likp occurs 0,
v_likp type t_likp.
data: begin of t_kna1,
kunnr like kna1-kunnr,
name1 like kna1-name1,
end of t_kna1.
data: begin of t_likp,
matnr like likp-matnr,
charg like likp-charg,
kunnr like likp-kunnr,
end of t_likp.
data: begin of v_output,
record(500),
end of v_ouput.
loop at i_kna1 into v_kna1.
concatenate: v_kna1-kunnr
v_kna1-name1
i want "v_likp-charg" to be here..******
into v_output seperated by c_tab.
append v_ouput.</b>
thanks,
You need to make a connection to the customer master file. In this case, you will have a 1 to many relationship with KNA1 and LIKP. Do you want to output only one record for each customer number?
Assuming that you already have the v_likp internal table, you can just read it with key.
loop at i_kna1 into v_kna1.
clear v_likp.
read table i_likp into v_likp with key kunnr = v_kna1-kunnr.
concatenate: v_kna1-kunnr
v_kna1-name1
v_likp-charg
into v_output seperated by c_tab.
append v_ouput.
Regards,
Rich Heilman
Similar Messages
-
How to write SELECT statement using tables ekko,ekpo and eket?
Hi,
I got a problem in performance tuning using below tables?
how to write SELECT statement using tables EKKO,EKPO and EKET and in conditon ( WHERE clause) use only fields
ekko~ebeln IN ebeln
ekko~loekz EQ ' '
ekko~lifnr IN lifnr
ekko~ekorg IN ekorg
ekko~ekgrp IN ekgrp
ekpo~werks IN werks
ekpo~pstyp EQ '3'
ekpo~loekz EQ space
ekpo~elikz EQ space
ekpo~menge NE 0
eket~rsnum NE space.
Thanks in Advance.
bye.Hi,
ekko~ebeln IN ebeln
ekko~loekz EQ ' '
ekko~lifnr IN lifnr
ekko~ekorg IN ekorg
ekko~ekgrp IN ekgrp
ekpo~werks IN werks
ekpo~pstyp EQ '3'
ekpo~loekz EQ space
ekpo~elikz EQ space
ekpo~menge NE 0 " Remove this from where clause
eket~rsnum NE space. " Remove this from where clause
' instead delete the entries after fetching into the table
DELETE it_itab WHERE menge EQ '0' AND rsnum EQ ' '.
Regards
Bala Krishna -
Need to Improve pefromance for select statement using MSEG table
Hi all,
We are using a select statement using MSEG table
which takes a very long time to run the program which is scheduled in back ground.
Please see the history below.;
1) Previously this program was using SELECT-ENDSELECT statement inside the loop i.e.
LOOP AT I_MCHB.
To get Material Doc. Details
SELECT MBLNR
MJAHR
ZEILE INTO (MSEG-MBLNR,MSEG-MJAHR,MSEG-ZEILE)
UP TO 1 ROWS
FROM MSEG
WHERE CHARG EQ I_MCHB-CHARG
AND MATNR EQ I_MCHB-MATNR
AND WERKS EQ I_MCHB-WERKS
AND LGORT EQ I_MCHB-LGORT.
ENDSELECT.
Endloop.
The program was taking 1 hr for 20 k data
2)The above statement was replaced by ALL ENTRIES to remove the SELECT-ENDSELECT from the loop.
***GET MATERIAL DOC NUMBER AND FINANCIAL YEAR DETAILS FROM MSEG TABLE
SELECT MBLNR
MJAHR
ZEILE
MATNR
CHARG
WERKS
LGORT
INTO TABLE I_MSEG
FROM MSEG
FOR ALL ENTRIES IN I_MCHB
WHERE CHARG EQ I_MCHB-CHARG
AND MATNR EQ I_MCHB-MATNR
AND WERKS EQ I_MCHB-WERKS
AND LGORT EQ I_MCHB-LGORT.
3)After getting the further technical analysis from BASIS team , And with the suggestion to optimize the program by changing the INDEX RANGE SCAN to
MSEG~M.
SELECT MBLNR
MJAHR
ZEILE
MATNR
CHARG
WERKS
LGORT
INTO TABLE I_MSEG
FROM MSEG
FOR ALL ENTRIES IN I_MCHB
WHERE MATNR EQ I_MCHB-MATNR
AND WERKS EQ I_MCHB-WERKS
AND LGORT EQ I_MCHB-LGORT.
At present the program is taking 3 to 4 hrs in back ground .
The table is complete table scan using index
MSEG~M.
Please suggest to improve the performance of this
many many thanks
deepakThe benchmark should be the join, and I can not see how any of your solutions can be faster than the join
SELECT .....
INTO TABLE ....
UP TO 1 ROWS
FROM mchb as a
INNER JOIN mseg as b
ON amatnr EQ bmatnr
AND awerks EQ bwerks
AND algort EQ blgort
And acharg EQ bcharg
WHERE a~ ....
The WHERE condition must come from the select on MCHB, the field list from the total results
you want.
If you want to compare, must compare your solutions plus the select to fill I_MCHB.
Siegfried
Edited by: Siegfried Boes on Dec 20, 2007 2:28 PM -
Performance tunning for select statements using likp lips and vbrp
Dear all,
I have a report where i am using select statements using first on likp the for all entries of likp i am taking data from lips and then for all entries in lips i am taking data from vbrp by matching VGBEL and VGPOS. Now the problem is that when it fetches data from vbrp it is taking lot of time around 13mins. to fetch data from vbrp. How can i overcome the problem.
regards
AmitHi,
there is also no secondary index for preceding document in VBFA table.
You will also have to create it here.
Regards,
Przemysław -
How to use a table name in the select statement using a variable?
Hi Everybody,
I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?
Regards,
Mallik.Hi all,
Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
for ex : select * from (tab_name) where....?
Can we do inner join on such select statements? If so how?
Thanks & Regards,
Mallik. -
SELECT statement INTO TABLE - what determines order of entries in in.table?
Hello everyone.
I habe a question: A select statement selects multiple entries from a data base table that are put into an internal table.
The question : What determines the order of the entries in the internal table?
And what might change the order all of a suddden in that internal table?
Could reorg. activities/archiving (even ongoing) cause any different result in the order as before ?
I do not mean different entries but I rather refer to the sorting of the internal table, if it is not explicitly stated in the select or in parts of the coding.
Any explaination is appreciated!
Thanks!
CN.Hi,
Its not the order in which you specify the fields in the where clause that affects the sequence of the selection.
What I said is that by default the entries are sorted by the primary key of the table.
I did a bit of a test out of curiosity and after seeing so many different replies on the thread. I was surprised to see the results of the different scenarios.
REPORT Z_TEST_SELECTION .
tables vbap.
data it_vbap type table of vbap.
data it_vbak type table of vbak.
select-options s_vbeln for vbap-vbeln.
select-options s_posnr for vbap-posnr.
"======================================================================
"s_vbeln has following entries
" 5
" 6
" 1
" 2
"s_posnr has following entries.
" 10
" Sorts in ascending order by VBELN and POSNR by default
select * up to 20 rows from vbap into table it_vbap.
refresh it_vbap.
"Below two cases are absolutely unreliable and I would suggest that a
"sort should be mentioned after these statements. So when we use select
"options specify values with the in clause, the sort is not reliable.
"Strangely , neither the sequence is not determined by the order in
"which the data was entered in the select option nor in the sequence of
"the primary key. And this is still a mystery to me about the order in which
"the entries are selected.
" Any answeres anyone ?
"1.
select * from vbap into table it_vbap
where vbeln in ('0000000002','0000000006','0000000005','0000000001')
and posnr in s_posnr.
* Resulted in
*900 |0000000001|000010|
*900 |0000000005|000010|
*900 |0000000006|000010|
*900 |0000000002|000010|
"=========================================================
"2.
select * from vbap into table it_vbap
where posnr in s_posnr
and vbeln in s_vbeln.
* Resulted in
*900 |0000000002|000010|
*900 |0000000001|000010|
*900 |0000000005|000010|
*900 |0000000006|000010|
refresh it_vbap.
"Here the orders were selected in Decending order of Sales order, however
"the posnr is not mentioned in the order by clause, hence posnr was
"still in ascending order.
select * from vbap into table it_vbap
where posnr in s_posnr and vbeln in s_vbeln
order by vbeln descending.
write : 'done!'.
refresh it_vbap.
"Here the orders were selected in Descending order of Sales order.
select * from vbak into table it_vbak where vbeln in s_vbeln
order by vbeln descending.
" The entries were selected in the ascending order of the key VBELN and
" POSNR, so it seems that for all entries does not affect the selection of records.
select * from vbap into table it_vbap
for all entries in it_vbak
where vbeln = it_vbak-vbeln
and posnr in s_posnr.
Of course if you change the order of the primary key (in the transparent table, not in the where clause), the entries will be sorted as per the changed key.
But we seldom change the the sequence of the primary key. In most cases we normally add a new field and make it a key field in addition to the existing key fields.
I hope this helps you.
There might be many more cases and examples than given above, which you can try and reply on this post. Lets see what we come up with.
regards,
Advait -
Problem with select statement using Ranges
Hi Guys,
I have used Ranges and used a select statement for selecting those ranges but I am facing a problem.
RANGES: r_doctyp for EDIDC-DOCTYP.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'DEBMAS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'MATMAS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'PRICAT'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'ORDERS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'INVOIC'.
append r_doctyp.
Select DOCNUM " IDoc number
DOCTYP " IDoc Type
from EDIDC into table IT_ZEDIDC
where CREDAT EQ s_credat-low
and DOCTYP EQ r_doctyp " IDOC Types
and DIRECT EQ '1'.
Here my select statement is only taking INVOIC.
But my statement should take any document type.
Thanks,
Prasad.Hi...,
Your following select statement is correct.
Select DOCNUM " IDoc number
DOCTYP " IDoc Type
from EDIDC into table IT_ZEDIDC
where CREDAT IN s_credat
and DOCTYP IN r_doctyp " IDOC Types
and DIRECT EQ '1'.
Why you are not getting result..
1. structure of the IT_ZEDIDC is having two fields DOCNUM , DOCTYP with same data lengths. If not it should be...
2. Order in the database table is must be similer to the order you maintained in the select statement.
3. As you are hard coding the input ranges make sure about every letter.
4. take a look at other where condition fields too.
5. check the table of the ranges in debugging mode.
6. why can't you declare separate work area and table for ranges...?
like .... data: r_tab type range of <field>
data: wa_tab like line of r_tab.
7. Use clear work area statement after the append statment.
--Naveen Inuganti. -
Advice required on a select statement using "FOR ALL ENTRIES"
Hi,
this is really intresting ...
I have a small requirement where in i have to find out
the valid entries in my internal table (T_MATNR) by using a select statement to a check table (MARA) which has all the fields present in the internal table T_MATNR.
Select statement is
SELECT MATNR
MTART
from MARA
for all entries in T_MATNR
into table T_MATNR
where matnr eq T_MATNR-MATNR.
If you observe the itab in the option 'FOR ALL ENTRIES' and the destination table is the same. I want to know whether this is correct? will it cause any performance issue? right now this statement is working fine for me.Hi,
U have to use
SELECT MATNR
MTART
from MARA
<b>into table I_MATNR(different table)</b>
for all entries in T_MATNR
where matnr eq T_MATNR-MATNR.
If u r specifying both same table name then for what entries it will retrieve, if u have alreay selected some entries and appending u can use
SELECT MATNR
MTART
from MARA
<b>into table T_MATNR</b>where matnr eq T_MATNR-MATNR.
then
SELECT MATNR
MTART
from MARA
<b>appending table T_MATNR</b>
for all entries in T_MATNR
where matnr eq T_MATNR-MATNR.
In this way u can do.
Hope u got it. -
Select statement from tables which have now been split
I used to select from 3 tables:
user, login, location
I would do:
select distinct user.id, login.computer_id, location.id as location_id
from user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = "manny"
but user has now been split into user1, and user2
I want to pull data where it exists from user1 or user2.
Much of the data in user1 is duplicated in user2 and vice versa, but I want to pull only one instance where it appears so that I can still get single row results of:
ID COMPUTER_ID LOCATION_ID
mannyd redstar_1 Bronx, NY
Any ideas on the query?Why would you split a single table into multiple tables with the same structure and much of the same data? That seems rather counterproductive.
I suppose you could do something like
select user.id, login.computer_id, location.id as location_id
from user1 user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = 'manny'
UNION
select user.id, login.computer_id, location.id as location_id
from user2 user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = 'manny'but that's obviously going to be much more expensive than the single-table approach...
Justin -
Select statement using BSEG table
Hello SAPinas,
I am using the following lines of code in one of my program. Becuase of that code I am getting Performance issue.
Note : BSEG is Cluster Table.
Could you please help me how I will use in another way
loop at t_hdr.
select buzei buzid koart shkzg mwskz dmbtr hwbas sgtxt vbund kostl
aufnr anln1 anln2 hkont kunnr lifnr matnr werks ebeln ebelp
zekkn rewrt prctr txjcd projk
into (t_item-buzei, t_item-buzid, t_item-koart, t_item-shkzg,
t_item-mwskz, t_item-dmbtr, t_item-hwbas, t_item-sgtxt,
t_item-vbund, t_item-kostl, t_item-aufnr, t_item-anln1,
t_item-anln2, t_item-hkont, t_item-kunnr, t_item-lifnr,
t_item-matnr, t_item-werks, t_item-ebeln, t_item-ebelp,
t_item-zekkn, t_item-rewrt, t_item-prctr, t_item-txjcd,
t_item-projk)
from bseg
where bukrs = t_hdr-bukrs
and belnr = t_hdr-belnr
and gjahr = t_hdr-gjahr
and hkont in s_hkont
and mwskz in s_mwskz
and kostl in s_kostl
and prctr in s_prctr
and werks in s_werks.
Skip record if not in selection screen range for state
check t_item-txjcd(2) in s_state.
if t_item-shkzg = c_debit. "S
endif.
if t_item-shkzg = c_credit. "H
t_item-dmbtr = t_item-dmbtr * ( -1 ).
t_item-rewrt = t_item-rewrt * ( -1 ).
t_item-hwbas = t_item-hwbas * ( -1 ).
endif.
**&MWB 04/08/2005 ... add additional US Bayer Tax dept requested fields
clear: t_item-basetax, t_item-accrtax, t_item-vendtax,
t_item-taxrate, t_item-invbase, t_item-invtax.
**&MWB ... end insert 04/08/2005
clear t_item-hwbas.
move-corresponding t_hdr to t_item.
append t_item.
clear t_item.
endselect.
endloop.
Thank you very much Advance.............:-)As BSEG is in a cluster table RFBLG, the only index available is the primary one, so only BUKRS, BELNR and GJAHR keys are actually available. So for other criteria resolution, the program will read the whole cluster, unpacking the records and executing the selection. When most criteria come from BKPF header, you may select from BKPF and then from BSEG using the full key of the cluster, and using a [FOR ALL ENTRIES|http://help.sap.com/abapdocu/en/ABENOPEN_SQL_PERFO.htm] IN a table with the keys from BKPF.
Try to use one or more of the secondary indexes provide by SAP
- BSAD Accounting: Secondary Index for Customers (Cleared Items)
- BSAK Accounting: Secondary Index for Vendors (Cleared Items)
- BSAS Accounting: Secondary Index for G/L Accounts (Cleared Items)
- BSID Accounting: Secondary Index for Customers
- BSIK Accounting: Secondary Index for Vendors
- BSIM Secondary Index, Documents for Material
- BSIS Accounting: Secondary Index for G/L Accounts
These indexes are actual tables, so you may create/use indexes, they are also easily appended, as they are filled via move-corresponding statements.
Try a little search at sdn on keywords like [BSEG, cluster and performance|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=bsegclusterperformance&adv=false&sortby=cm_rnd_rankvalue].
Regards -
SELECT statement using XML data taking way too long.
Hi all, I am using SQL Server 2005.
I have an issue which I find hard to describe. The server that I am using contains two test databases which are (supposed to be) identical. They both have tables named EVENTS with identical fields. I am using XML data to query and update data to this table.
When I run the SELECT in one database, against the EVENTS table it takes a long time. The longest I've kept it running is 2:30 minutes. When I run it against the EVENTS table in the other database the results are almost instantaneous. I've created a test
query to duplicate this behavior:
declare @ValidXMLInput xmlset @ValidXMLInput = '<EVENTS>
<EVENT EID="8077" EDATE="2014-07-20 10:15"
USERID="GTJ789" LOCID="7016" STATE="0" />
</EVENTS>'
SELECT Col.value('@EID','VARCHAR(5)'),Col.value('@STATE','INT')
FROM @ValidXMLInput.nodes('//EVENTS/EVENT') Tab(Col)
left join tblEvents on
tblEvents.EvIdNum=Col.value('@EID','VARCHAR(5)') And
tblEvents.EvDate=Col.value('@EDATE','DATETIME') And
tblEvents.UserId=Col.value('@USERID','VARCHAR(8)') And
tblEvents.EvLocId=Col.value('@LOCID','VARCHAR(8)')
where tblEvents.EvIdNum Is Null
Basically, the above query returns all rows in the XML table that are not in the database table. The results are then passed on to other statements.The columns in the join are key fields for tblEvents and have a PK index for both tables (in each db).
Now the issue that I am having. When I use an EID in the XML data of any other value (as presented in the example above), such as '3477' the query runs fast on both databases; however, when I specifically use an EID of '8077' then the query slows down to
a point where it takes more than 2:30 minutes (after which I cancel the execution). This only happens with one of the databases.
For testing purposes I've created an XML structure with only one item. Both tables have approximate 111 million records. One table contains about 900K records with an EID of 8077. The other table contains about 930K records with this EID. There aren't many
differences in the data. The records with the EID of 8077 (the slow one) are for different dates, users and locations. I should also mention that although the data presented here for EID consists of number, provisions exist where the number may be prefixed
by a letter; hence the varchar designation.
My question to you all is: How can I start troubleshooting this issue? Should I be looking at indexes?
I had some doubt about this because the query is fast for other EIDs. Why would it get "stuck" with this particular one?
Any troubleshooting advice is welcomed. Thanks! Saga
Insanity is the prelude to discoverySome thoughts:
Is there a hardware difference between the two databases ? E.g. are they on the same disk (array) ?
Is there anything else running on your server besides your SQL instance ?
Do you see spikes in I/O, CPU or both ?
Maybe there is locking on one DB that's not happening in the other.
You should check indexes and statistics plus compare estimated execution plan between the two DBs.
Also check this links:
http://technet.microsoft.com/en-us/library/ms345118%28v=sql.90%29.aspx
http://technet.microsoft.com/en-us/library/ms345115%28v=sql.90%29.aspx -
Getting a dumb after writing a SELECT statement at TABLE level of SMART
hi all,
i have created a RATE COMPARISON REPORT.In that Report i have to display Rate Price against RFQ No.For this purpose i have write a code at SMART FORMS in TABLE.Following are the code:
SELECT SINGLE netpr
INTO it_detail
FROM ekpo
INNER JOIN ekko ON
ekko~ebeln = ekpo~ebeln
WHERE ekko~BSTYP EQ 'F'
AND ekko~spras eq 'E'
AND ekpo~ebeln eq IT_DETAIL-EBELN
This code is assign with TEXT FILED at TABLE level.when i execute it i get the following dump.
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CXSY_OPEN_SQL_DB', was not caught in procedure "%CO2" "(FORM)"_,
nor was it propagated by a RAISING clause.Since the caller of the procedure could not have anticipated that the exception would occur, the current program is terminated.
The reason for the exception is:
In a SELECT access, the read file could not be placed in the target field provided. Either the conversion is not supported for the type of the target field, the target field is too small to include the value, or the data does not have the format required for the target field.
could any body tell me what is problem in my SELECT query statement after executing giving me a dump.
Thanks,
sappk25Hi
The select query is wrong, as you should not move the single field into a table (it_detail)....
Change the query as follows...
data: v_netwr type netwr.
SELECT SINGLE netpr
INTO v_netwr
FROM ekpo
INNER JOIN ekko ON
ekkoebeln = ekpoebeln
WHERE ekko~BSTYP EQ 'F'
AND ekko~spras eq 'E'
AND ekpo~ebeln eq IT_DETAIL-EBEL
if sy-subrc eq 0.
move v_netwr to it_detail.
endif.
Hope this helps.... -
How to pass a parameter into a select statement using a bulk collect
Using a cursors I can use execute immediate to pass a parameter to specify a table name.
I have modified the procedure not to use the cursor. I am using a collection using a bulk insert into a nested table. How can I specify the table the table name as a parameter without using the execute immediate statement.
Thank youHi Donald,
The functionality of using a parameter in a function is only available in the formula editor and not in SQL Expression. Parameters cannot be passed to the SQL Expression, the main purpose of the SQL Expression is to make use of Database functions to make calculations at the database level but the current functionality of the product only allows you to use Database fields.
There is an article that talks on SQL Expressions and can be useful http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=c2016184&sliceId=&dialogID=6018612&stateId=1%200%206020316
Regards,
Vinay -
How to get accurate values for select statement using single column
Hi All,
Below is my query which runs fine
Select Distinct Top 4
FiscalYearId,
FiscalMonthOfYearId
From ODS.Common.tODS_Date
Inner Join
UTL.Utility.tUTL_ProcessDate
On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate
And tUTL_ProcessDate.DatabaseName = 'ODS'
Order By
FiscalYearId Desc,
FiscalMonthOfYearId Desc
Below is the generate output
FiscalYearId FiscalMonthOfYearId
2014 2
2014 1
2013 12
2013 11
But i want to use this query in one of my where clause condition as its being used in the where clause it can only return 1 row.So, i tried something like this
Select Distinct Top 4
FiscalMonthOfYearId
From ODS.Common.tODS_Date
Inner Join
UTL.Utility.tUTL_ProcessDate
On tODS_Date.DateShort < tUTL_ProcessDate.ProcessDate
And tUTL_ProcessDate.DatabaseName = 'ODS'
Order By
FiscalMonthOfYearId Desc
And the result set of this one gives me the output like
FiscalMonthOfYearId
12
11
10
9
Which is not correct,( if you see the result set above).
Can someone please help me with any ides on this.If you want to use this query in the WHERE clause, then use it with EXISTS option which allows to return more than 1 column.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
I have 2 tables
Table Parent_child_table:
ID | Parent_id | Name
1 | NULL | Kitchen
2 | 1 | Freezer
3 | NULL | Garden
4 | 3 | Grass
Table Products:
ID | parent_child_table_ID | Price | Comment
1 | 2 | 111 | aaaa
2 | 4 | 12 | vv
I want to select Name from parent table where selected child ID are in PRODUCT table.....
The result would like:
|NAME|
|Kitchen
|Garden
Can someone help with this SQL SELECT ?Raivis wrote:
I have 2 tables
Table Parent_child_table:
ID | Parent_id | Name
1 | NULL | Kitchen
2 | 1 | Freezer
3 | NULL | Garden
4 | 3 | Grass
Table Products:
ID | parent_child_table_ID | Price | Comment
1 | 2 | 111 | aaaa
2 | 4 | 12 | vv
I want to select Name from parent table where selected child ID are in PRODUCT table.....
The result would like:
|NAME|
|Kitchen
|Garden
Can someone help with this SQL SELECT ?A guess
select
p.name
from Parent_child_table p
where p.parent_id is null
and exists
select
null
from Parent_child_table p1, products p2
where p1.id = p2. parent_child_table_id
and p1.parent_id = p.id
)The reason it's a guess is because you've really done nothing to outline WHY you should get the results you say you would like. The more time you spend creating a clear question, the less time you'll have to spend weeding through useless answers.
Cheers,
Maybe you are looking for
-
Is there a way to confirm iPad Notes are backed up after a sync?
I'm skeptical that everything on my iPad is backed up to my new MacBook Air because I have been getting that stupid common error message ever since I first connected the two, about iPad being synced to another iTunes library already and if I want to
-
I want to upgrade my macbook pro mid 2010's ram
I want to upgrade my macbook pro's ram to 8gb's I don't want to spend $200 on ram from apple, i Know that with buying it from apple, if it doesnt work they will do it for you, and it guranteed to work, i just don't have the money to do that. they out
-
Write ALL XY Data to Spreadsheet
Hi I have 4 XY Plots I would like to export to a spreadsheet, following this procedure or something similar: Run Stop BOTH While loops (to stop collecting data) Save all data from all 4 XY Plots to the SAME spreadsheet. (preferably with a prompt for
-
Is there a way to find all the locked files my computer?
I am having trouble importing some files into Aperture and I discovered that one of the reasons might be that some of the files are locked. I know how to unlock them but I'd like to find the locked files and unlock them all at once. Is there a way to
-
Unable to write smartlist, error code 1060301
Hi Team Members, we are trying to use Essbase Studio to create Essbase cube by using relational db tables. while doing that we are getting following Error. Note:_ we have tried it with partitioned table & Normal Tables bt result are same. rational ta