Help with multiple table joins
I'm trying to limit the results of a query joining multiple tables. I have a main table, tbl_webrequests, and multiple tables with supporting information. The unique column for tbl_webrequests is reqID. There is another table, tbl_instructions, that holds all the instructions tied to each request. I join the tables using reqID.
I'm trying to construct a page that has all of the records in tbl_webrequests. The problem I'm having is that with each request that has multiple instructions, I have multiple results because of the multiple instructions for one reqID. For now, all I want is the original instruction to display. Below is the original query, and below that is what I'm trying to get the query to do for each record in tbl_webrequest. Note that 319 is a random uniqueID in tbl_webrequests.
SELECT
DISTINCT W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
W.closingNotes, W.mins, W.requestTypeID, I.instructions, I.instID
from tbl_webrequests W left join
(select reqID, instID, instructions from tbl_instructions) I on W.reqID = I.reqID
ORDER BY I.instID asc;
SELECT
distinct I.instructions, I.instID, W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
W.closingNotes, W.mins, W.requestTypeID
from tbl_webrequests W left join
(select reqID, instID, instructions from tbl_instructions where rowNum = 1 and reqid = 319 order by instID asc) I on W.reqID = I.reqID
where W.reqID = 319
ORDER BY I.instID asc;
My question is, how do I pass the reqID as a variable into the join subquery so that the query returns only returns the first joined item in tbl_instructions for each record in tbl_webrequests?
Any help is appreciated
Thanks!
Scrap the "DISTINCT" and try something like this:
Select
I.Instructions, I.Instid
, W.Reqid, W.Dt_Close, W.Dt_Due, W.Subject, W.Statusid, W.Empid, W.Priorityid
, W.Assigneeid, W.Categoryid, W.Url, W.Hrs, W.Closingnotes, W.Mins, W.Requesttypeid
From Tbl_Webrequests W Left Join
( Select Reqid, Instid, Instructions
From Tbl_Instructions I0
Where Instid = (Select Min(Instid) From Tbl_Instructions I1
Where I1.Reqid = I0.Reqid)
) I On W.Reqid = I.Reqid
Where W.Reqid = 319
Order By I.Instid Asc;;)
Similar Messages
-
Select List or Radio Buttons query with multiple tables join
Hello,
I'm having a problem creating a select list or a radio group item.
I need to display the emp_first_name in the select list but have the return value of the order_id in the select list or radio buttons item.
The tables are as follow:
emp_table
emp_id
emp_first_name
emp_last_name
etc...
orders_table
order_id
order_name
emp_id
etc...
I need to display the emp_name from emp_table in the select list but return the order_id from the orders_table as the return value.
How can I do this?
Any help would be greatly appreciated.
Thanks.
Regards,
NJHi NJ,
Try:
select e.emp_first_name d,
o.order_id r
from orders_table o
inner join emp_table e on o.emp_id = e.emp_id
order by 1You may have an issue with an emp_id being used for more than one order and, therefore, the employee's name appearing more than once in the list?
Andy -
Hello -
HELP!!!!! I need to join the following tables so I can compare the totals of colVal1+colVal2+colVal3 in tblIMP with ColTOTAL_NVal in AnotherDB.dbo.BL
Below are the important columns along with relationships from the tables. Is this even possible?
tblIMP
PK IMP integer
TNum
colVal1
colVal2
colVal3
colVal4
tblSC
PK IntCNum numeric(7,)
FK ISN numeric(8,0)
TNum
tblSD
PK IntSLNum numeric(7,0)
FK ISN
tblSH
PK ISN numeric(8,0)
Sh_ID nvarchar(25)
AnotherDB.dbo.BL
PK BL_ID integer
Sh_ID nvarchar(100)
ColTOTAL_NVal
TNum in tblIMP has duplicates (not for the row, but for TNum itself)
TNum in tblSC has duplicates also (not for the row, but for TNum itself)
tblSH has a one-to-many relationship with tblSC;
tblSH has a one-to-many relationship with tblSD;
tblSD has a one-to-many relationship with tblSC
tblSC is a recursive table – think container with many TNum in it
ANY HELP AT ALL WILL BE APPRECIATED!!!
JuniormintThanks for your response, Latheesh.
I would have posted the DDL, sample data and desired output, but I'm on a contract job and am unable to divulge that information. Is there anything that is not understandable with what I have posted? If so, please let me know.
Juniormint
You need to atleast explain us with some INDICATIVE data how your tables hold information and how you want the output to appear. Otherwise its hard for us by just looking at some table structure alone as we cant see your system neither knows your rules.
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
BaseTableName blank when calling GetSchema on a query with multiple tables
I am using ODP.NET 11.2.0.3.0 and when calling GetSchemaTable on a DataReader that contains a join the returned SchemaTable has the BaseTableName and BaseColumnName fields blank - this is different than what I see with the Oracle OLE DB Provider and with how SQL Server's native provider works. I can't find any discussion of this - is this on purpose or is it a bug? why does the available schema information vary so drastically between a single table query and a query with multiple tables joined?
Thanks,
Bryan HintonHi Bryan,
I am also facing the same issue. Did u find any work around or any suggestions will be well appreciated.
Thanks,
Naresh. -
1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed in the stat plan ?
2. Does rowsource statistics gives some kind of understanding of Extended stats ?You can get Row Source Statistics only *after* the SQL has been executed. An Explain Plan midway cannot give you row source statistics.
To get row source statistics either set STATISTICS_LEVEL='ALL' in the session that executes theSQL OR use the Hint "gather_plan_statistics" in the SQL being executed.
Then use dbms_xplan.display_cursor
Hemant K Chitale -
How to build a form with multiple tables in oracle application express
Hi everyone,
I have got problem in building a form with multiple tables.I have a main table with (20) columns and this main table is related to the other tables with the primary key-foreign key relation ship.My requirement is i have to build a form which has fields from many tables and all the fields are related to the main table using (ID) column.In that form if i enter ID field i have to get information from differnt tables.
Please help me to solve this (building a form with mutiple tables)
Thank you
sansSans,
I am no Apex expert, but with a situation as "complex" as yours, have you thought about creating a VIEW that joins these 7/8 tables, placing an INSTEAD OF trigger on that view to do all the business logic in the database, and base your application on the view?
This is the "thick-database" approach that has been gaining momentum of late. The idea is to put your business logic in the database wherever possible, and let the application (Form, Apex, J2EE, whatever) concentrate on UI issues, -
Query with multiple outer joins
I had a doubt with whether the following kind of query is valid with multiple outer-joins. The format of the query is something like this:-
select A.col1, B.col2
from table1 A, table2 B, table3 C where
A.col3=B.col4(+) and B.col5=C.col6(+)
This would mean the follwoing with regard to outer-joins in the query.
1) fetch records with col3 in table A matching or not matching col4 in table B
2) fetch records with col5 in table B matching or not matching col6 in table C
So, this query is valid?
I hope, my question is clear.
Please, help in solving the doubt.
regardsThis is valid and it works fine
-
Create opaque view in OBIEE with multiple tables
Hi,
I need some help with the opaque view since i have never created it in past. I want to create an opaque view which fetches data from multiple tables. Is it possible to do that ? Or is there any other alternate option available in OBIEE ? I read the following blog and other similar blogs on opaque views but could not find option to use it for query with multiple tables:
Oracle Business Intelligence: Creating Opaque View in Physical Layer in OBIEE 10g
Also can you please advice how to join two tables from different databases in OBIEE ?
Kindly advice.
Regards,
AndyHi Andy,
As per my knowledge you can create Opaque View on one table at a time.Joining two tables from different databases yes we can create a report from multiple data sources.Check this
Rittman Mead Consulting » Blog Archive » Reporting Against Multiple Datasources in OBIEE
Mark if helps.
Thanks, -
Create View table with multiple table
I want to create View table with relation with multiple tables.
for ex
table 1
mrnno
mrnqty
table 2
mrnno
issqty
table 3
mrnno
retqty
want to create view table where i can see the sum (mrnqty), sum(issqty),sum(retqty) group by mrnno
sandyHi
CREATE OR REPLACE FORCE VIEW my_view AS
WITH t1 AS
(SELECT mrnno,
SUM(mrnqty) sum1
FROM table_1
GROUP BY mrnno),
t2 AS
(SELECT mrnno,
SUM(issqty) sum2
FROM table_2
GROUP BY mrnno),
t3AS
(SELECT mrnno,
SUM(retqty) sum3
FROM table_3
GROUP BY mrnno)
SELECT mrnno,
sum1,
sum2,
sum3
FROM t1,t2,t3
WHERE t1.mrnno = t2.mrnno
AND t1.mrnno = t3.mrnnoCheers
Ben
http://www.munkyben.wordpress.com
Don't forget to mark replies helpful or correct ;) -
Help with multiple httpservice calls
I need help with multiple httpservice call back to back, doing 10 different mysql query at startup of the app loading results into 14 datagrids/combobox all queries are to different tables.
Hello,
I think what Grizzzzzzzzzz means is the following:
<mx:HTTPService id="serviceOne"
url="here goes url"
result="resultHandler1(event);"
fault="faultHandler(event);"/>
<mx:HTTPService id="serviceTwo"
url="here goes url"
result="resultHandler2(event);"
fault="faultHandler(event);"/>
<mx:HTTPService id="serviceThree"
url="here goes url"
result="resultHandler3(event);"
fault="faultHandler(event);"/>
// Result handler 1
private function resultHandler1(event:ResultEvent):void{
//Here do something with the results
xmlCollection = event.result as XML;
//then call the next service
serviceTwo.send();
// Result handler 2
private function resultHandler2(event:ResultEvent):void{
//Here do something with the results
xmlCollection = event.result as XML;
//then call the next service
serviceThree.send();
I hope this helps,
Pierre -
Sample coding for multiple table join
Hi,
i need a sample coding for multiple table join. can anyone help me out.
regards
GokulSELECT AVBELN AFKDAT AVTWEG ASPART AWAERK AKURRF AKUNAG AKNUMV
BPOSNR BFKIMG BNETWR BMATNR
DBEGRU ELABOR E~MATKL
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM VBRK AS A INNER JOIN VBRP AS B
ON AVBELN EQ BVBELN
INNER JOIN J_1IEXCHDR AS C
ON AVBELN EQ CRDOC
INNER JOIN KNVV AS D
ON DKUNNR EQ AKUNAG AND
DVKORG EQ AVKORG AND
DSPART EQ ASPART AND
D~BEGRU NE SPACE
INNER JOIN MARA AS E
ON EMATNR EQ BMATNR
WHERE A~FKDAT IN S_FKDAT AND
A~FKART EQ 'F2' AND
A~VTWEG IN S_VTWEG AND
A~SPART IN S_SPART AND
A~KUNAG IN S_KUNAG AND
A~FKSTO NE 'X' AND
B~WERKS IN S_WERKS AND
C~TRNTYP = 'DLFC' AND
E~LABOR IN S_LABOR AND
C~SRGRP IN ('01','02','03','31','32','33','41','42','43',
'81','82','83','95','55','45', '48') AND
B~MATNR IN S_MATNR AND
D~BEGRU IN S_BEGRU AND
E~MATKL IN S_MATKL.
but my suggestion not to use more than 2 table in inner join it will affect in performance use for all entries instead of join.
regards
shiba dutta -
Context index can't be used in complicated multiple tables join?
hello
thank you for view this page.
i have a comlicated sql :
SELECT count(*)
from
((app_AssetBasicInfo left join app_AssetBasicInfoExt on
app_AssetBasicInfo.id=app_AssetBasicInfoExt.id) left join
(app_AssetCustominfo1 left join app_AssetCustominfoExt1 on
app_AssetCustominfo1.id=app_AssetCustominfoExt1.id) on
app_AssetBasicInfo.id=app_AssetCustominfo1.id) WHERE
app_AssetBasicInfo.CategoryID=1 AND Del_tag=0 and contains(description,'department')>0;
the table app_AssetBasicInfo and app_AssetBasicInfoExt have multiple columns and large recoord size. i create a context index on app_assetbasicinfoext(description) which description is 4000 varchar2.
but the sql doesn't use context index. i suspect that the complicated multiple table join can't use context index? does it correct?
thanks very much!Could you please post an explain plan? I'm not quite sure what is the issue.
-
Please I need some help with a table
Hi All
I need some help with a table.
My table needs to hold prices that the user can update.
Also has a total of the column.
my question is if the user adds in a new price how can i pick up the value they have just entered and then add it to the total which will be the last row in the table?
I have a loop that gets all the values of the column, so I can get the total but it is when the user adds in a new value that I need some help with.
I have tried using but as I need to set the toal with something like total
totalTable.setValueAt(total, totalTable.getRowCount()-1,1); I end up with an infinite loop.
Can any one please advise on some way I can get this to work ?
Thanks for reading
CraigHi there camickr
thanks for the help the other day
this is my full code....
package printing;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
import javax.swing.table.*;
import java.text.DecimalFormat;
public class tablePanel
extends JDialog implements Printable {
BorderLayout borderLayout1 = new BorderLayout();
private boolean printing = false;
private Dialog1 dialog;
JPanel jPanel = new JPanel();
JTable table;
JScrollPane scrollPane1 = new JScrollPane();
DefaultTableModel model;
private String[] columnNames = {
private Object[][] data;
private String selectTotal;
private double total;
public tablePanel(Dialog1 dp) {
dp = dialog;
try {
jbInit();
catch (Exception exception) {
exception.printStackTrace();
public tablePanel() {
try {
jbInit();
catch (Exception exception) {
exception.printStackTrace();
private void jbInit() throws Exception {
jPanel.setLayout(borderLayout1);
scrollPane1.setBounds(new Rectangle(260, 168, 0, 0));
this.add(jPanel);
jPanel.add(scrollPane1, java.awt.BorderLayout.CENTER);
scrollPane1.getViewport().add(table);
jPanel.setOpaque(true);
newTable();
addToModel();
addRows();
setTotal();
public static void main(String[] args) {
tablePanel tablePanel = new tablePanel();
tablePanel.pack();
tablePanel.setVisible(true);
public void setTotal() {
total = 0;
int i = table.getRowCount();
for (i = 0; i < table.getRowCount(); i++) {
String name = (String) table.getValueAt(i, 1);
if (!"".equals(name)) {
if (i != table.getRowCount() - 1) {
double dt = Double.parseDouble(name);
total = total + dt;
String str = Double.toString(total);
table.setValueAt(str, table.getRowCount() - 1, 1);
super.repaint();
public void newTable() {
model = new DefaultTableModel(data, columnNames) {
table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer,
int row, int col) {
Component c = super.prepareRenderer(renderer, row, col);
if (printing) {
c.setBackground(getBackground());
else {
if (row % 2 == 1 && !isCellSelected(row, col)) {
c.setBackground(getBackground());
else {
c.setBackground(new Color(227, 239, 250));
if (isCellSelected(row, col)) {
c.setBackground(new Color(190, 220, 250));
return c;
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (e.getClickCount() == 1) {
if (table.getSelectedColumn() == 1) {
table.setTableHeader(null);
table.setModel(model);
scrollPane1.getViewport().add(table);
table.getColumnModel().getColumn(1).setCellRenderer(new TableRenderDollar());
public void addToModel() {
Object[] data = {
"Price", "5800"};
model.addRow(data);
public void addRows() {
int rows = 20;
for (int i = 0; i < rows; i++) {
Object[] data = {
model.addRow(data);
public void printOut() {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(tablePanel.this);
pj.printDialog();
try {
pj.print();
catch (Exception PrintException) {}
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.black);
int fontHeight = g2.getFontMetrics().getHeight();
int fontDesent = g2.getFontMetrics().getDescent();
//leave room for page number
double pageHeight = pageFormat.getImageableHeight() - fontHeight;
double pageWidth = pageFormat.getImageableWidth();
double tableWidth = (double) table.getColumnModel().getTotalColumnWidth();
double scale = 1;
if (tableWidth >= pageWidth) {
scale = pageWidth / tableWidth;
double headerHeightOnPage = 16.0;
//double headerHeightOnPage = table.getTableHeader().getHeight() * scale;
//System.out.println("this is the hedder heigth " + headerHeightOnPage);
double tableWidthOnPage = tableWidth * scale;
double oneRowHeight = (table.getRowHeight() + table.getRowMargin()) * scale;
int numRowsOnAPage = (int) ( (pageHeight - headerHeightOnPage) / oneRowHeight);
double pageHeightForTable = oneRowHeight *numRowsOnAPage;
int totalNumPages = (int) Math.ceil( ( (double) table.getRowCount()) / numRowsOnAPage);
if (pageIndex >= totalNumPages) {
return NO_SUCH_PAGE;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
//bottom center
g2.drawString("Page: " + (pageIndex + 1 + " of " + totalNumPages), (int) pageWidth / 2 - 35, (int) (pageHeight + fontHeight - fontDesent));
g2.translate(0f, headerHeightOnPage);
g2.translate(0f, -pageIndex * pageHeightForTable);
//If this piece of the table is smaller
//than the size available,
//clip to the appropriate bounds.
if (pageIndex + 1 == totalNumPages) {
int lastRowPrinted =
numRowsOnAPage * pageIndex;
int numRowsLeft =
table.getRowCount()
- lastRowPrinted;
g2.setClip(0,
(int) (pageHeightForTable * pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(oneRowHeight *
numRowsLeft));
//else clip to the entire area available.
else {
g2.setClip(0,
(int) (pageHeightForTable * pageIndex),
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(pageHeightForTable));
g2.scale(scale, scale);
printing = true;
try {
table.paint(g2);
finally {
printing = false;
//tableView.paint(g2);
g2.scale(1 / scale, 1 / scale);
g2.translate(0f, pageIndex * pageHeightForTable);
g2.translate(0f, -headerHeightOnPage);
g2.setClip(0, 0,
(int) Math.ceil(tableWidthOnPage),
(int) Math.ceil(headerHeightOnPage));
g2.scale(scale, scale);
//table.getTableHeader().paint(g2);
//paint header at top
return Printable.PAGE_EXISTS;
class TableRenderDollar extends DefaultTableCellRenderer{
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean isFocused,
int row, int column) {
setHorizontalAlignment(SwingConstants.RIGHT);
Component component = super.getTableCellRendererComponent(
table,
value,
isSelected,
isFocused,
row,
column);
if( value == null || value .equals("")){
( (JLabel) component).setText("");
}else{
double number = 0.0;
number = new Double(value.toString()).doubleValue();
DecimalFormat df = new DecimalFormat(",##0.00");
( (JLabel) component).setText(df.format(number));
return component;
} -
F4 Help with text table in WD abap
Hi,
i am using country related input help with check table T005 in one of table and i want to display the country text along with country id in my table, f4 for country is coming however if i select country from f4 it showing country id in the input field of table.
i want to have country text also in one of my input fields in the table, i have seen f4 help works if we have explicit search help and using parameter assignment we can have id and text defaulted if we use same context for id and text fields, however in this case country table t005 has check table t005 where texts are stored in text table t005t so web dynpro abap is't picking up the texts??
please suggest how can i get the texts as soon as i select country in the f4??Hi Kranthi,
You merely have to have an internal table storing list of countries, which you only need to do once, e.g. on load of application (method WDDOINIT of COMPONENTCONTROLLER). In your view, you have to declare a method for event onEnter of the input field, but this method doesn't have to have any code. Your code will be in method WDDOBEFOREACTION, where you read get country name from country key. Once you've got country name, transfer value to a context attribute to which you've already mapped as a source for attribute value of the UI element.
Check out SAP Webdynpro component FITV_IMG_DEFHTLCATA -> view V_ITEM. -
Hello All,
I need some help with custom tables. I have created a custom table to maintain names and I also did table maintenance generation so that the user can maintain names in this table using SM30 transaction.
The question is, in my program on the selection screen when the user press F4 I need to display the values maintained in this custom table...
Can anyone help me with this.
Thanks
PavanIf I understood you correctly, you have a program in which one or some of the selection screen fields refer to a custom database table field(s).
You want to implement a F4 functionality.
Fill an internal table with the values you want to show.
Call the function module 'F4IF_INT_TABLE_VALUE_REQUEST' in the event AT SELECTION-SCREEN ON VALUE-REQUEST FOR MYPARAM as follows.
call function 'F4IF_INT_TABLE_VALUE_REQUEST'
exporting
retfield = MYITAB-FIELD
dynprofield = MYSELSCREENPARAM
dynpprog = sy-cprog
dynpnr = sy-dynnr
value_org = 'S'
tables
value_tab = my_f4_itab.
Srinivas
Maybe you are looking for
-
Trying to view pdf version of school textbook in Safari
Hi- I am trying to view the online version of our class science textbook (grade 12 Science-Toronto, Canada) - we have registered it and have the correct user name and password- but keep getting an error 403 message when we try to view the pdf (http:/
-
Header pricing condition types
Hi, In a purchase order header pricing condition types are appearing twice . Ex: JCDB 254 JCDB 20 JCV1 345 JCV1 30. first condition type (ex: JCDB 254) is calculated on net price second cond type (ex: JCDB 20) is calcu
-
Hi, I am planning to take the Flash 8 certification exam, but I can`t find any information about it. Could somebody tell me if there is a Flash 8 certication exam ? or it doesn´t exist? Where do I find information? Is it a good choice to take the Fla
-
I am classifying traffic using NBAR and Access-lists, setting DSCP values, and then useing bandwidth percentages to reserve bandwidth for protected classes in times of high utilization. I currently have this setup on my outside interface (connecting
-
Assign varaible a value based on a condition
How can I assign a conditional numerical value to one variable based on the value of a xml tag. I.e. if it's "company A" assign it 12 if it's "company B" assign it 17. Also be able to use that value later on in the template. Thanks in advance