简体   繁体   中英

Querying same column from two different tables

I would like to get every patch_no that specyfic champion is at like eg 'Katarina' and then I would like to sort those Patches with Created column which is in different table, Patch_No are connected between tables.

SELECT Patch_No 
  FROM champions , info 
 WHERE Champion = 'Katarina'
 ORDER BY Created DESC

Sample info table:

ID  Patch_No  Created  
165 1.0.0.126 2015-08-22 21:20:03
164 1.0.0.125 2015-08-22 21:03:40
163 1.0.0.124 2015-08-22 19:28:12
162 1.0.0.123 2015-08-22 19:03:59
161 1.0.0.122 2015-08-22 18:12:19
160 1.0.0.121 2015-08-22 17:30:26
159 1.0.0.120 2015-08-21 23:19:16
158 1.0.0.119 2015-08-21 22:13:31
157 1.0.0.118 2015-08-21 21:53:44

And Sample champions table :

ID Patch_No Champion
66 1.0.0.32 Ashe
67 1.0.0.32 Cho’Gath
68 1.0.0.32 1-leimerdinger
69 1.0.0.32 Karthus
70 1.0.0.32 Katarina
71 1.0.0.32 Nunu

You are doing good, just use INNER Join To get desired result. You can use ASC or DESC in Order by clause based on how you want to soreted out data.

SELECT C.Patch_No 
  FROM champions C
     INNER JOIN info I ON C.Patch_No  = I.Patch_No 
 WHERE Champion = 'Katarina'
 ORDER BY Created DESC

you can use this query too :

SELECT C.Patch_No 
FROM champions C, info I 
WHERE  C.Patch_No  = I.Patch_No 
AND Champion = 'Katarina'
ORDER BY Created DESC

;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM