2017-06-20 4 views
0

私は3つの列PrjId、prjname、stationを持つテーブルを持っています。私はドロップダウンリストにproject_detailテーブルからプロジェクトを取得したいデータベース内の単一の値を選択する(テーブルに複数の類似した値がある場合)#

PrjId  prjname  station 
1   test1  s1 
1   test1  s2  
1   test1  s3 

: は、ここに私のテーブルの一例です。 は、ここに私のSQLクエリ

select * from project_detail where prjname <> '' and PrjId is not null; 

問題ではなく、すべての3 test1のドロップダウンに表示されている1つのtest1のプロジェクトのです。私はいくつかの状態を入れなければならないことを知っていますが、私はそれを行う方法を理解していません。ピーズヘルプ。

+0

トップ1か別の試しましたか? –

+1

[SQLで一意のレコードを選択する方法](https://stackoverflow.com/questions/1641718/how-to-select-unique-records-by-sql)の可能な複製 – unicorn2

答えて

2
select Distinct prjname 
from project_detail where prjname <> '' and PrjId is not null; 
0

あなたの要件はDISTINCTキーワード

select DISTINCT prjname 
from project_detail 
where prjname <> '' and PrjId is not null; 

これはあなたのテーブルでユニークprjnameのリストを与えるためのものです。

しかし、そのテーブルにはまともでないようなものがあります。

プロジェクトが多くのステーションに存在し、ステーションに多数のプロジェクトが存在するプロジェクトとステーションの関係を記述したい場合は、3つのラウンドテーブル、プロジェクト用と1つのそれはあなたのために働くことができ、プロジェクトや駅

Project_Detail 
--------------- 
idproj 
prjname 
....other specific project attributes 

Station_Detail 
---------------- 
idstation 
stname 
....oter specific station attributes 

Project_Station 
---------------- 
idprj 
idstation 
....other specific relationship attributes 
....like for example dateofinstall,active etc... 
0
select Distinct PrjId, prjname from project_detail where prjname <> '' and PrjId is not null; 

との関係のためのステーションと1。

関連する問題