SQL查詢表中兩個字段對應的另表的資料,應該怎麼操作

2021-03-29 00:24:59 字數 4604 閱讀 3093

1樓:匿名使用者

根據 news表中的 news_type_id = 1 查出 news_type表中的 「透明點評」 這條資料,「透明點評」是最後需要查出來的位置資料。

子查詢或者表連線

比如表連線的方式就可以寫成:

select n.id,t.type_name,title from news as n inner join news_type as t onnn.

news_type_id=t.type_id;

只查「透明點評」的資料子查詢可以寫成:

select * from news where news_type_id=(select type_id from news_type where type_name='透明點評');

2樓:匿名使用者

sql查詢乙個表中兩個字段對應的另乙個表的資料,可以通過如下操作進行:輸入語句:select a.

* from test a,test1 b where a.id=b.id and a.

name=b.name;

sql查詢乙個表中兩個字段對應的另乙個表的資料

3樓:匿名使用者

根據 news表中的 news_type_id = 1 查出 news_type表中的 「透明點評」 這條資料,「透明點評」是最後需要查出來的位置資料。

子查詢或者表連線

比如表連線的方式就可以寫成:

select n.id,t.type_name,title from news as n inner join news_type as t onnn.

news_type_id=t.type_id;

只查「透明點評」的資料子查詢可以寫成:

select * from news where news_type_id=(select type_id from news_type where type_name='透明點評');

4樓:匿名使用者

select a.* from a,b where a.id=b.id and a.name=b.name

sql:怎樣根據乙個表種的字段id 查出 另乙個表中的 資料 20

5樓:我看的是你看我

例如:兩個表中

的news_type_id 跟 type_id是對應的,根據news 表中的 news_type_id =1 查出 news_type 表中的 type_name

根據 news表中的 news_type_id = 1 查出 news_type表中的 「透明點評」 這條資料,「透明點評」是最後需要查出來的位置資料。

比如表連線的方式就可以寫成:

select n.id,t.type_name,title from news as n inner join news_type as t on n.

news_type_id=t.type_id;

只查「透明點評」的資料子查詢可以寫成:

select * from news where news_type_id=(select type_id from news_type where type_name='透明點評');

6樓:

子查詢或者表連線

比如表連線的方式就可以寫成:

select n.id,t.type_name,title from news as n inner join news_type as t on n.

news_type_id=t.type_id;

只查「透明點評」的資料子查詢可以寫成:

select * from news where news_type_id=(select type_id from news_type where type_name='透明點評');

7樓:匿名使用者

select news.id,news.news_type_id,news_type .type_name,news.title

from news

left join news_type on news.news_type_id=news_type .type_id

where news.news_type_id =1

8樓:匿名使用者

select news.id,news_type.typename,title from news inner join news_type on news_type.

news_type_id=news.id and news .news_type_id=1

9樓:匿名使用者

select *

from news n

left join news_type nt on nt.type_id = n.news_type_id

where nt.type_name='透明點評'

10樓:東歌

select type_name from news_type a left join news b on a.type_id=b.news_type_id where news_type_id='1'

11樓:匿名使用者

兩表根據兩個字段關聯即可

如 select distinct b.type_name from news a,news_type b where a.news_type_id= b.

type_id and a.news_type_id = '1'

sql資料庫,請問如何查詢乙個表兩個字段內容和另乙個表兩個字段內容完全相同的記錄?

12樓:匿名使用者

需要用連線查詢來處理。

如有以下2張表:

查詢2張表id和name欄位內容完全相同的內容,可用如下語句:

select a.* from test a,test1 b where a.id=b.id and a.name=b.name;

結果:說明,兩表連線where條件要寫上關聯條件,因為提問是兩個字段完全相等,所以就寫作:a.id=b.id and a.name=b.name

13樓:

select a1.* from a1,a2

where a1.b1=a2.b1 and a1.b2=a2.b2;

14樓:匿名使用者

select a1.b1, a1.b2, a1.b3

from a1 inner join a2 on a1.b1 = a2.b1 and a1.b2 = a2.b2

sql語句如何查詢乙個表中某兩個欄位的相同資料?

15樓:

除重select distinct a.id as aid,a.name as aname,b.

id as bid,b.name as bname from a inner join b on(a.name=b.

name and a.id=b.id)

不除重select a.id as aid,a.name as aname,b.

id as bid,b.name as bname from a inner join b on(a.name=b.

name and a.id=b.id)

16樓:匿名使用者

select * from a

inner join b on a.name = b.name and a.id = b.id

where a.name = '張三' and a.id = '008'

內連線即可

17樓:輕癮

select name,id,count(*) from a group by name,id

18樓:青龍襲天

select * from a where a.name=b.name and a.id=b.id

應該是這個了吧

sql中如何根據乙個字段查詢兩個表關聯欄位並修改

19樓:yang_追風少年

update 表zhia a

set a.欄位

dao內1 = 值

容1,   a.欄位2 = 值2,

a.欄位3 = 值3

where exists (select 1from 表b b

where a.關聯字段 = b.關聯欄位and a.欄位 = 值

and b.欄位 = 值)

20樓:匿名使用者

update b  set b.欄位

dua =(

zhiselect max(a.欄位a) from 表dao1 a where a.id =b.

id)版from 表2 b where b.id in (select id from 表1);

--或者權

update b set b.欄位a=a.欄位a from 表1 a ,表2 b where a.id=b.id

用一條sql語句同時更新表中的兩個字段

update 表名 set 欄位1 5 欄位2 100 where 欄位3 0101 前面的and 換成逗號,最後那個0101要用單引號引起來 前面幾位都沒有發現啊 資料型別是 int 是 不需要 引號的 你要把報錯發上來,你發個語句看不出來的。update 表名 set 欄位1 5,欄位2 100...

SQL如何根據兩個字段排序,SQL如何按兩個字段排序,乙個按倒序乙個按公升序

1 首先建一張測試表coal blead,裡面有多個欄位2 我們輸入 select from coal blead order by q price 語句,按q price欄位進行公升序排序 3 我們輸入 select from coal blead order by q desc,price de...

sql語句查詢根據表中列該列在兩個不同

1 在計 bai算機中,開啟foxtable軟體,新建du乙個表 zhi格,比如學生的評價成績dao表內,並輸入資料,如下圖所示。容2 接著,滑鼠左鍵單擊選擇選單下的 雜項 如下圖所示。3 然後,在選單欄目中,滑鼠左鍵單擊 sql查詢 如下圖所示。4 接著,在 sql查詢 視窗上,選擇資料來源,如下...