mysql資料庫中有兩條重複的資料,,但是id是不一樣的,但是我想在前臺顯示出來的資料是id較大的那一條數

2021-04-26 06:22:25 字數 1136 閱讀 8698

1樓:匿名使用者

select max(id) id,nickname,tel,`

daogroup`,ali_pid,ad_pid,pid from 表名

專屬 group by nickname,tel,`group`,ali_pid,ad_pid,pid

在mysql資料庫中如何讓某個欄位有重複的只取一條

2樓:魚尾摯愛白菜

select *

from table  ###

where not exists (

select * from table  ###where # = #

and ## < ##

)在使用mysql時,有時需要查詢出某個欄位不重複的記錄,雖然mysql提供 有distinct這個關鍵字來過濾掉多餘的重複記錄只保留一條,但往往只用它來返回不重複記錄的條數,而不是用它來返回不重記錄的所有值。其原因是 distinct只能返回它的目標欄位,而無法返回其它欄位,這個問題讓我困擾了很久,用distinct不能解決的話,只有用二重迴圈查詢來解決。

給個例子把,比如:表table_a 4條資料id a b c d

01 ab 1a2 1b2 121

02 ab 2a3 3b3 4a1

03 ac 1a2 1b2 121

04 ac 2a4 3b2 52g

何讓a欄位重複取條 比

01 ab 1a2 1b2 121

03 ac 1a2 1b2 121

保留相同a值id行

select *

from table_a a

where not exists (

select 1 from table_a bwhere b.a = a.a

and b.id < a.id)

3樓:匿名使用者

select max(id) as id,fid,title,date from table group by fid,title,date

4樓:尋_常

select * from (select * from a order by id desc) as b group by fid

mysql把資料庫中的資料複製到另資料庫中的表表結構相同

1。表結構相同的表,且在同一資料庫 如,table1,table2 sql insert into table1 select from table2 完全複製 insert into table1 select distinct from table2 不復制重複紀錄 insert into ta...

PHP從MYSQL資料庫中隨機讀取若干條資料,並將資料合併為一條資料,在賦值給變數。要怎麼實現

隨機選取 select from 表名 order by rand limit 你想要的數量 我不知道你的合併是什麼意思,如果就是單純的累加,那當你處理results的時候,就用 符號連線即可。你要隨機,表裡就給有一個id function rands num,max return a a impl...

在mysql資料庫中如何讓某個欄位有重複的只取一條

保留相 同a值的最小id行 select from table a a where not exists select 1 from table a bwhere b.a a.a and b.id a.id select from table a where id in select min id ...