inner-join

SQL: How to create two fields based on same field from another table?

不想你离开。 提交于 2019-12-11 05:27:17
问题 I am sure this is quite easy to find, but through my searching I have been unable to find a solution. I'm probably not looking for the right keywords, so hopefully someone can help me. I have two tables and I am trying to run a select query that will create two new fields based on the same field from another table. Example: Table1 contains two fields called AgencyCountryCode and ClientCountryCode so I need to create two new fields called AgencyCountryName and ClientCountryName . In Table2 I

Different JOIN values depending on the value of another column

≡放荡痞女 提交于 2019-12-11 05:16:07
问题 I have 2 tables j and c. Both tables have columns port and sec. For j.port = ABC, I want to join the 1st 6 characters of c.sec with the 1st 6 characters of j.sec. For other j.ports, I want to join c.sec = j.sec How can I do that ? select c.port,j.port,c.sec,j.sec from j, c where c.SEC = CASE WHEN j.port = 'ABC' then SUBSTRING(c.sec,1,6) = SUBSTRING(j.sec,1,6) --> something like this else j.sec 回答1: Performance wise breaking this into two may be beneficial. The complex join condition will

Join dataframes by column values pandas

一世执手 提交于 2019-12-11 05:03:32
问题 I have two data frames df1 and df2 taken from different databases. Each item in the dataframes is identified by an id . df1 = pd.DataFrame({'id':[10,20,30,50,100,110],'cost':[100,0,300,570,400,140]}) df2 = pd.DataFrame({'id':[10,23,30,58,100,110],'name':['a','b','j','d','k','g']}) there are some common products in both dataframes, in this case those with the ids: 10,30,100,110. I want to merge this information in one single dataframe, as this one: df3 = pd.DataFrame({'id':[10,30,100,110],

MySQL complex subquery formulation

给你一囗甜甜゛ 提交于 2019-12-11 04:57:45
问题 I have two tables - books and images . books has columns like id , name , releasedate , purchasecount . images has bookid (which is same as the id in books, basically one book can have multiple images. Although I haven't set any foreign key constraint), bucketid , poster (each record points to an image file in a certain bucket, for a certain bookid ). Table schema: poster is unique in images , hence it is a primary key. Covering index on books: ( name , id , releasedate ) Covering index on

insert into with combination of inner join

你。 提交于 2019-12-11 04:48:30
问题 How can I make an insert statement of this select statement? SELECT et FROM user inner join petrazafa.class_room using(id) where title like '%11%' or title like '%12%'; I need to insert into all et = 1; thanks 回答1: Edit 1 : I think there's an answer here : Use select query inside the Insert query for the same table name For you : INSERT INTO `yourtable`(et) SELECT et FROM user inner join petrazafa.class_room using(id) where title like '%11%' or title like '%12%'; Watch doc : INSERT ... SELECT

mysql muliple joins from same colums with different keys

我怕爱的太早我们不能终老 提交于 2019-12-11 04:07:13
问题 I need some help making the second join with the tables below. I got some help from here previously where it was suggested I need to add a second JOIN, however, this is where I'm stuck and need some assistance. wp-posts ----------------- id | Post_Title | ----------------- 01 | Event 1 | ----------------- 02 | Event 2 | ----------------- wp-postmeta ------------------------------------------------------- meta_id | post_id | meta_key | meta_value | ---------------------------------------------

join 2 tables case sensitive upper and lower case

放肆的年华 提交于 2019-12-11 03:48:50
问题 I have 2 tables and need to get result on brand code. In the database i have for example 2 different brands but their code is the same (only difference in lower and upper case). For example: code Name ab Nike AB Adidas How to inner join 2 tables on code to get this 2 separately? Right now after inner join i get total sum of this 2. SELECT Code, BrandName, Count(*) QTY, SUM(Price) TOTAL FROM A INNER JOIN B ON A.Code=B.Code GROUP BY Code, BrandName This query will give me wrong result as it

Selecting rollup after join

假如想象 提交于 2019-12-11 03:43:15
问题 Moved from UX post I have 2 queries with roll up in each one.. SELECT DATE(date) AS day, COUNT(IF(name = 'red', 1, NULL)) AS "red", COUNT(IF(name = 'blue', 1, NULL)) AS "blue", COUNT(IF(name = 'yellow', 1, NULL)) AS "yellow" FROM test1 GROUP BY day with rollup SELECT DATE(date) AS day, COUNT(*) AS total FROM test2 GROUP BY day with rollup When joining them the rollup row gets removed so I solved it by using another query calculating the rollup and union it to the end of the result Here's a

Where clause versus inner join statement checks, are they the same? [duplicate]

╄→гoц情女王★ 提交于 2019-12-11 03:24:37
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Condition within JOIN or WHERE Are the below 2 queries the same? SELECT u.* FROM User u INNER JOIN Sales s ON (u.userId = s.userId) WHERE u.active = 1 AND s.amount > 0 AND s.status = 1 versus: SELECT u.* FROM User u INNER JOIN Sales s ON (u.userId = s.userId AND s.amount > 0 and s.status=1) WHERE u.active = 1 Are these 2 queries the same in terms of result set always? Performance considerations? 回答1: The SQL

Select duplicates query returns duplicates MYSQL

流过昼夜 提交于 2019-12-11 01:57:07
问题 I have the following query that I want to return all the duplicated rows to the user for them to decide which one to use: SELECT * FROM `table` INNER JOIN (SELECT * FROM table GROUP BY barcode HAVING (COUNT(id) > 1)) dup ON `table`.`column` = `dup`.`column` Each part of this query appears to return the correct response but when adding the 2 together I am getting duplicates of the duplicates if that makes sense. Any ideas on what is going on? My table data +----+------------------------+------