left-join

How to join mysql tables

假装没事ソ 提交于 2020-01-14 09:32:11
问题 I've an old table like this: user> id | name | address | comments And now I've to create an "alias" table to allow some users to have an alias name for some reasons. I've created a new table 'user_alias' like this: user_alias> name | user But now I have a problem due my poor SQL level... How to join both tables to generate something like this: 1 | my_name | my_address | my_comments 1 | my_alias | my_address | my_comments 2 | other_name | other_address | other_comments I mean, I want to make a

SQL Standard Regarding Left Outer Join and Where Conditions

白昼怎懂夜的黑 提交于 2020-01-12 18:50:54
问题 I am getting different results based on a filter condition in a query based on where I place the filter condition. My questions are: Is there a technical difference between these queries? Is there anything in the SQL standard that explains the different recordsets from the queries? Given the simplified scenario: --Table: Parent Columns: ID, Name, Description --Table: Child Columns: ID, ParentID, Name, Description --Query 1 SELECT p.ID, p.Name, p.Description, c.ID, c.Name, c.Description FROM

SQL Standard Regarding Left Outer Join and Where Conditions

大城市里の小女人 提交于 2020-01-12 18:50:08
问题 I am getting different results based on a filter condition in a query based on where I place the filter condition. My questions are: Is there a technical difference between these queries? Is there anything in the SQL standard that explains the different recordsets from the queries? Given the simplified scenario: --Table: Parent Columns: ID, Name, Description --Table: Child Columns: ID, ParentID, Name, Description --Query 1 SELECT p.ID, p.Name, p.Description, c.ID, c.Name, c.Description FROM

Pandas merge using dfA column == dfB index [duplicate]

不打扰是莪最后的温柔 提交于 2020-01-11 11:56:12
问题 This question already has answers here : Pandas Merging 101 (2 answers) Closed 2 years ago . How to merge (left join) using column value from dataframe A and index of dataframe B? For example: >>> A >>> B lkey value rkey value 0 foo 1 0 foo 5 1 bar 2 1 bar 6 2 baz 3 2 qux 7 3 foo 4 3 bar 8 to get: lkey value_x rkey value_y 0 foo 1 bar 6 1 bar 2 qux 7 2 baz 3 bar 8 3 foo 4 NaN NaN 回答1: try using left_on and right_index to do the merging, like: m = pd.merge(dfA, dfB, right_index = True, left_on

Pandas merge using dfA column == dfB index [duplicate]

落花浮王杯 提交于 2020-01-11 11:56:04
问题 This question already has answers here : Pandas Merging 101 (2 answers) Closed 2 years ago . How to merge (left join) using column value from dataframe A and index of dataframe B? For example: >>> A >>> B lkey value rkey value 0 foo 1 0 foo 5 1 bar 2 1 bar 6 2 baz 3 2 qux 7 3 foo 4 3 bar 8 to get: lkey value_x rkey value_y 0 foo 1 bar 6 1 bar 2 qux 7 2 baz 3 bar 8 3 foo 4 NaN NaN 回答1: try using left_on and right_index to do the merging, like: m = pd.merge(dfA, dfB, right_index = True, left_on

get the opposite results from a SELECT query

微笑、不失礼 提交于 2020-01-11 10:26:18
问题 these are my tables: `room`(roomID,roomNum) `customer`(customerID,Surname,etc) `contract`(contractID,roomID,weekNum) `paymen`t(paymentID,customerID,contractID,YearKoino) and when i use the following query: `select` room.roomnum `from` payment,contract,room,customer `where` payment.contractID = contract.contractID `and` contract.roomID=room.roomID `and` customer.customerID=payment.customerID `and` contract.weeknum='40' `and` payment.YearKoino='2007' ; the results i am getting are: +---------+

get the opposite results from a SELECT query

南笙酒味 提交于 2020-01-11 10:26:08
问题 these are my tables: `room`(roomID,roomNum) `customer`(customerID,Surname,etc) `contract`(contractID,roomID,weekNum) `paymen`t(paymentID,customerID,contractID,YearKoino) and when i use the following query: `select` room.roomnum `from` payment,contract,room,customer `where` payment.contractID = contract.contractID `and` contract.roomID=room.roomID `and` customer.customerID=payment.customerID `and` contract.weeknum='40' `and` payment.YearKoino='2007' ; the results i am getting are: +---------+

Difference between IS NULL criteria in JOIN and WHERE in a query

冷暖自知 提交于 2020-01-11 06:43:11
问题 create table #t1 (id int) create table #t2 (id int) insert into #t1 values (1) insert into #t1 values (2) insert into #t1 values (3) insert into #t2 values (1) insert into #t2 values (2) I ran the below queries, and I get 2 different outputs. Second is the desired output. I cannot understand the reason for output given by query1. Please assist me to understand the result. -- Query1 select * from #t1 a left join #t2 b on a.id = b.id and b.id is null -- Query2 select * from #t1 a left join #t2

Oracle (+) outer join and constant values

℡╲_俬逩灬. 提交于 2020-01-10 19:45:18
问题 I'm running into an issue with which I can't figure out how to correctly configure a join. I'm using reporting software that utilizes the (+) indicators in the WHERE clause for our Oracle database. I have two tables: CHECK and TRANSACTION. A check can have multiple transactions, but a transaction doesn't necessarily have a corresponding check. Both tables have indicators identifying current records called CURRENT that is either a 'Y' or 'N'. Join option 1: Select * FROM TXN,CHK WHERE TXN.CHK

Multiple left joins on multiple tables in one query

ぃ、小莉子 提交于 2020-01-10 09:34:11
问题 I've got one master table, which has items stored in multiple levels, parents and childs, and there is a second table which may or may not have additional data. I need to query two levels from my master table and have a left join on my second table, but because of the ordering within my query this will not work. SELECT something FROM master as parent, master as child LEFT JOIN second as parentdata ON parent.secondary_id = parentdata.id LEFT JOIN second as childdata ON child.secondary_id =