简体   繁体   中英

Best SQL Option for Performance

I currently need to execute a database query that involves data from three separate tables. ( )

The table looks like the following 表如下所示



The table looks like the following 表如下所示



The table has the following schema 表具有以下架构



I am working on a transaction inquiry that involves data from all of these tables. I need to return this data in a TransactionItem that I am populating from these three tables

The TransactionItem as a Pojo looks like the following

public TransactionItem(){

    private String firstName;
    private String lastName;
    private String email;
    private String baseName;
    private String city;
    private String state;
    private Date date;

    public String getFirstName(){
              return firstName;
    }
    public String setFirstName(String firstName){
              this.firstName = firstName;
    }
    ...
    ...///The rest of the getters and setters
    ...
    ...


}



Currently I am doing three separate selects from each table, which is taking longer then I would like. I would image that there is a way I could use a join or nested select statements,etc.

The data and conditions and their corresponding tables are as follows

I need...

from

I need

and from where from is equal to from ,并从 等于从

Again there is more that I need, but it is redundant to name them off, The idea should still be clear, I need to query data that is dependent on each other. I am not sure performance wise what is the best performance option. The amount of data that is being traversed could end up being very large or very small(not sure if that matters).

select b.name,b.state, s.city,s.state,s.duty,s.branch,s.date, m.first_name,m.last_name,m.email,m.phone,m.id,s.transaction_id from bases as b, sell_transaction as s, member as m where s.agentId is null and s.username = m.username and b.base_id = s.duty
select first_name, last_name, member.id member_id, bases.name, bases.state
from bases, sell_transaction, member
where sell_transaction.base_id = bases.base_id
and member.id = sell_transaction.agentId;

I am going out on a limb here and guessing that agentID is the connection to member from sell_transaction , but it's not clear or obvious, and possibly incorrect (unless you clarify your data model).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM