Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a sells tables that stores every sell operation
i know that it's not good to store every sell data row and give it the product name or client name as strings, that will use large data size
i've to store the sell operation with the client id as int
but what to do when retrieveing data by select query?
it returns the client id's but i need a query to returns client name as it stored in clients table
what is the best query to do that?

What I have tried:

is that join statements or union or what?
after 1 year(for example) there will be a huge number of rows related to clients and product names by id
what statement should i use to handle that huge number of rows?
Posted
Updated 16-May-17 9:43am
Comments
[no name] 16-May-17 14:48pm    
SELECT
SELLS.X,
SELLS.Y,
SELLS.Z,
CLIENT.ID,
CLIENT.NAME
FROM SELLS
LEFT JOIN CLIENT ON CLIENT.ID = SELLS.CLIENT_ID
WHERE ...
Maciej Los 16-May-17 15:30pm    
We cannot read in your mind or direct from your screen. You have to provide more details...

1 solution

Please, read the comments to the question first.

I'd suggest to start with basics: Tutorial: Writing Transact-SQL Statements | Microsoft Docs[^]

As Bruno (0x01AA[^]) mentioned in the comment to the question, to fetch data, you have to use SELECT statement[^]. You can "link" 2 tables by using joins[^], see: Visual Representation of SQL Joins[^]

So, an example SELECT statement can look like this:
SQL
SELECT so.OperationId, so.Stuff, so.ClientId, ci.ClientName
FROM SellOperation AS so INNER JOIN Clients AS ci ON so.ClientId = ci.ClientId
WHERE so.ClientId = @ClientId


Good luck!
 
Share this answer
 

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