Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get all raws of a table and only one of an other table, a think like this:

select * from table_1 and select id_prod from table_2

What I have tried:

I tried to write query with heidi but without success
Posted
Updated 18-Oct-19 1:49am
v2

You need to use JOIN, see examples here: SQL Joins[^]

Another option is UNION, this can also be used for non-related tables: SQL UNION Operator[^]

To select only one row use TOP: SQL SELECT TOP, LIMIT, ROWNUM[^]
 
Share this answer
 
v3
Comments
Member 14594285 18-Oct-19 5:34am    
yes but with join I select all rows that have a correspondence, I want only a specific raw
RickZeeland 18-Oct-19 5:42am    
You can also use DISTINCT in combination with a WHERE clause, see the examples on the W3Schools website. It pays to study SQL as it is used almost everywhere.
This will take all rows from 1st table and only 1st row from second table
SQL
select * from myTable
union all (select top 1 * from myTableDuplicate)

Output
Id	fName	
1	Srikanth
2	sunil	
3	Shilpa	
1	Srikanth


This will take all the columns from the first table and only Id column from the second table
SQL
select * from myTable M
join (select ID from myTableDuplicate) as D on M.Id=D.ID


Output
Id	fName		ID
1	Srikanth	1
2	sunil		2
3	Shilpa	    3
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900