MySQL Select all columns from one table and some from another table
Just use the table name:
SELECT myTable.*, otherTable.foo, otherTable.bar...
That would select all columns from myTable
and columns foo
and bar
from otherTable
.
Select only specific columns in SQL joins and assign `alias`
You can do so and give new aliases to your columns,in below query i have given a short name p
to Portfolio
so to select all columns from Portfolio
you can use only p.*
same for Client
and Provider
table
SELECT p.* ,
c.Name AS 'Client Name' ,
pr.Name AS 'Provider Name'
FROM Portfolio p
INNER JOIN Client c ON p.Client_id=c.id
INNER JOIN Provider pr ON c.Provider_id = pr.id
Joining two tables with specific columns
This is what you need:
Select e.EmpName, e.Address, s.Name, S.Address, s.Project
From tbEmployees e
JOIN tbSupervisor s on e.id = SupervisorID
You can read about this on W3Schools for more info.
Inner join 3 tables with only specific columns selected
Use the alias name
SELECT a.*,
b.*,
c.id, c.ime, c.prezime
FROM `ugovori-artikli` AS a
INNER JOIN `ugovori` AS b
ON a.`ugovor_id` = b.`id`
INNER JOIN `ids` AS c
ON b.`kupac_id` = c.`id`
AND a.`artikal` = ?
Hope this helps :)
MySQL inner join for specific column
Just use it with the table name as alias:
SELECT product.product_id,
product.product_name,
product.price,
product_image.id,
product_image.product_id,
product_image.product_image1,
product_image.added_on,
product_image.modified_on
FROM product_image
INNER JOIN product ON product_image.product_id = product.product_id
ORDER BY product_image.id DESC
This way you make sure you take the columns from the table you want to.
SELECT COLUMNS FROM INNER JOIN
When you select from query you should name it as well.
Try this:
SELECT D.firstname,D.surname
FROM (SELECT A.firstname,A.surname,I.ACNUM,I.FIELDNUM
FROM ACADEMIC A
INNER JOIN INTEREST I ON (A.ACNUM = I.ACNUM)
INNER JOIN SUBJECT S ON (I.FIELDNUM = S.FIELDNUM)
WHERE S.TITLE = 'History') D;
Join two data frames, select all columns from one and some columns from the other
Not sure if the most efficient way, but this worked for me:
from pyspark.sql.functions import col
df1.alias('a').join(df2.alias('b'),col('b.id') == col('a.id')).select([col('a.'+xx) for xx in a.columns] + [col('b.other1'),col('b.other2')])
The trick is in:
[col('a.'+xx) for xx in a.columns] : all columns in a
[col('b.other1'),col('b.other2')] : some columns of b
MySQL - specific columns on join?
This will only include User.FirstName
and Provider.ProviderID
in the final resultset:
SELECT User.FirstName, Provider.ProviderID FROM User LEFT OUTER JOIN Provider ON User.ProviderID = Provider.ID
Related Topics
Oracle Table Column Name with Space
Invalid Column Name on SQL Server Update After Column Create
How to Allow Only One Row for a Table
How to Specify 'Default' as a SQL Parameter Value in Ado.Net
For Autoincrement Fields: Max(Id) VS Top 1 Id Order by Id Desc
How to Get Windows Log-In User Name for a SQL Log in User
Transact-SQL Shorthand Join Syntax
Postgresql Function Definition in Squirrel: Unterminated Dollar-Quoted String
Workaround for Ora-00997: Illegal Use of Long Datatype
SQL Oracle Left Join and Subquery Error: Ora-00905: Missing Keyword
Can Insert [...] on Conflict Be Used for Foreign Key Violations
How to Read a Text File Using T-Sql