2010-08-05 112 views
0

我的目標是從存在大量重複值的「EmbedImgDimension」列中選擇值。Mysql:如何從數據庫列中選擇不同的值

我用下面的查詢

select 
    distinct EmbedImgId, 
    VideoID, 
    EmbedImgHeight, 
    EmbedImgWidth, 
    EmbedImgFileName, 
    concat(embedimgwidth,' x ',embedimgheight) as EmbedImgDimension 
    from embedimages 
    inner join Video on Video.schoolid=#Value# 
    where embedimages.isdeleted=0 order by embedimages.embedimgwidth asc; 

笏修改應該怎麼做在此查詢,以便從「EmbedImgDimension」 column.Any幫助將十分讚賞選擇唯一值。

謝謝。

回答

3
select 
    distinct concat(embedimgwidth,' x ',embedimgheight) as EmbedImgDimension 
    from embedimages 
    inner join Video on Video.schoolid=#Value# 
    where embedimages.isdeleted=0 order by embedimages.embedimgwidth asc; 

更新

說你也想不同的視頻ID是一個邏輯問題。你想得到一個結果,每個維度只出現一次,對嗎?那麼,你怎麼能期望獲得所有不同的videoID結果呢?想象你有

videoid dimension 
     1  1x1 
     2  1x1 
     3  2x2 
     4  2x2 

也許你可以告訴我你想得到哪個結果。 但是你要麼得到1x1和2x2,要麼你會得到1,2,3,4 - 當你想要維度唯一性的時候,你不能也得到所有不同的視頻文件,看看我的意思?

+0

如果你想獲得不同的值,你必須刪除非獨特的值(如video_ids)。你現在的方式,數據庫試圖找到video_id,EmbedImgId等獨特的組合(這可能是獨特的,所以你不會得到任何分組) – Nicolas78 2010-08-05 09:57:14

+0

@ nicolas78:謝謝朋友......但我也需要實施 選擇 不同EmbedImgId, VideoID的, EmbedImgHeight, EmbedImgWidth, EmbedImgFileName我的查詢......所以笏可以做... – GethuJohn 2010-08-05 10:02:27

+0

檢查我的更新。我認爲你想在邏輯上不可能,但也許你可以進一步詳細說明 – Nicolas78 2010-08-05 10:07:19

1

EmbedImgDimension列中使用distinct關鍵字。

+0

你能向我解釋一下在當前查詢 – GethuJohn 2010-08-05 09:53:54

+0

中必須進行的修改,例如: 'select distinct(concat(「test」,col_name))from table_name' – thelost 2010-08-05 09:56:59

+0

謝謝..讓我試試 – GethuJohn 2010-08-05 10:04:57