Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have these tables:
table1: id,name,item_id
item: id,name
itembarcode: id,item_id,barcode

in itembarcode table every item_id has many barcode

i make the following sql:

select a.*, as itemname,c.barcode from table1 a,item b,itembarcode c where<>0 and and c.item_id=a.item_id

in this statement i get every record in table1 but repeated for every barcode in itembarcode for every item
i want to select in only one of barcodes for every item (any barcode of it) "no repeat"

what can i do in this statement?

1 solution

Try this:
select distinct a.*, as itemname,
(select top 1 c1.barcode from itembarcode c1 where c1.item_id=c.item_id)
table1 a,item b,itembarcode c where and c.item_id=a.item_id

Suggest you learn to use JOIN [^] in future.
M. Daban 23-Jul-14 4:38am
Yes, its work thankyou
Peter Leow 23-Jul-14 6:20am
You are welcome.

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