How to write Join Query for two tables without foreign key in Yii2?

Let’s learn how to write Join Query for two tables without foreign key in Yii2. The most accurate or helpful solution is served by Stack Overflow.

There are ten answers to this question.

Best solution

Yii2 : How to write Mysql query to select records from two tables using left join

I have two tables which i want to join... i.e. camps & cities. I have write the query in PHP for this... but I want same query in Yii2 format... Please tell me how can i write this query in yii2...?? Here is my query : SELECT DISTINCT camps.city_id, camps.state_id, cities.city_name from camps LEFT JOIN cities ON cities.state_id = camps.state_id WHERE camps.state_id = 5 AND camps.status = '1' ORDER BY cities.city_name ASC


The equivalent with ActiveQuery can be like this: Camp::find() ->select(['city_id', 'state_id',...

Read more

Santosh Gaikwad at Stack Overflow Mark as irrelevant Undo

Other solutions

Why would you not use a join when doing a SQL query between two tables?

Why would one use the following query: select a.item, b.item from a,b where = Instead of: select a.item, b.item from a join b on =


The two queries as presented are identical. The latter syntax has the ability to be extended to other...

Read more

Amrith Kumar at Quora Mark as irrelevant Undo

How do I join multiple tables in a mysql query?

I already know how to join two tables or even three, but my situation is a little different....I have a table of mobile homes for sale....I have a second table of the parks those homes are in. I have a third table of bank repossesions that exist in mobile...


Hi, Here I am assuming that table PARK with mobile homes is related to table MOBILEHOME. So I have joined...

Read more

BA at Yahoo! Answers Mark as irrelevant Undo

Apache Hive: Join two similar tables using HiveQL?

This is the below Table2 data which I am getting back from this query as suggesred by Robert Morton. select user_id, prod_and_ts.product_id as product_id, prod_and_ts.timestamps as timestamps from testingtable2 LATERAL VIEW explode(purchased_item) exploded...


I believe UNION ALL is the supported syntax. Also, some implementations of hive require union all's...

Read more

Michael Bailey at Quora Mark as irrelevant Undo

Help with simple MySQL Query?

I am using an INNER JOIN to return a table with two joined tables. The problem is that both tables have the identical field name called "id". How do I write a query that will return as id1 and as id2 and the rest of the...


Well, you could try something like the following: select table1.*, table2.*, as id1, table...

Read more

MK at Yahoo! Answers Mark as irrelevant Undo

Query from different database Connections Oracle SQL develoepr?

Is it possible to write a query over two different database connections (both are oracle databases - they have different sign on credentials etc) I'm trying to join sales data on a server in the UK to product data on a server in France. Can I do this...


This would be dependent on your programming language - typically you create a connection object or something...

Read more

Leon S at Yahoo! Answers Mark as irrelevant Undo

Apache Hive: How can I join these two tables using HiveQL?

CREATE EXTERNAL TABLE IF NOT EXISTS Table1   (This is the MAIN table through which comparisons need to be made)     (     BUYER_ID BIGINT,     ITEM_ID BIGINT,     CREATED_TIME STRING     )   And this is the data in the above first table     **BUYER_ID...


There are a couple of challenges to this question so I'll break them up individually. The end goal will...

Read more

Robert Morton at Quora Mark as irrelevant Undo

What is the best strategy for SQL queries that join tables across database clusters?

We're starting to keep different tables in different clusters as our database size grows. As a result, simple queries that joined two tables are no longer simple -- I've been getting the results from one table, and using that result to construct the...


The short answer is, unfortunately, no. Welcome to the miserable world of scaling. The database is going...

Read more

Rick Branson at Quora Mark as irrelevant Undo

Why Hive's Sort Merge Bucket Map Join does the join in just one mapper?

I have a Hadoop cluster and I use Hive for querying. I have  two large tables, which are bucketed and sorted on the join key. So, I  think using "sort merge bucket map join" would be helpful. I set the required flags and then run the query...


It's tough to say without taking a look at the explain plan and/or the mapreduce job's job.xml because...

Read more

Mark Grover at Quora Mark as irrelevant Undo

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.