Jump to content

[SOLVED] Query Help


Recommended Posts

What i am trying to do is get all videos where the game has a console of #123, and has a group of #12345.

Now i have to do it differently because the consoles are not in the video table, they are in the game table.

 

SELECT

video.groups,video.randname,games.consoles,video.timestamp,video.id

FROM

video,

games

WHERE

video.groups LIKE "%12345%"

AND

games.consoles LIKE "%123%"

LIMIT 3

 

That query is, when i do while($row=mysql_fetch_array...etc, outputting 3 of the same video randnames. It outputs 3 of the same video id's.

 

Help please?

 

Link to comment
Share on other sites

Tables:

table: video

important rows:

id int(30)

randname int(8)

gameid int(10)

groups text

 

table: games

id int(30)

name text

consoles text

 

Samples:

Games:

id: 8

name: Half Life 2

consoles: 4,8,9

 

Video:

id: 6

randname: 57954341

gameid: 8

groups: 78239

 

 

Now i want to get all videos which it's game has the console number 4, and that are in the group 78239. I can get the group, but getting the console of the game is different, i'm not sure how to do it.

Link to comment
Share on other sites

well i normally i would create another table for consoles and link it in..

but you could do this

SELECT video.id, games.id, video.groups,video.randname,games.consoles,video.timestamp
FROM
video, games
WHERE
video.groups LIKE "%12345%"
AND
CONCAT(',', games.consoles, ',') LIKE "%,4,%"
GROUP BY video.id, games.id
LIMIT 3

 

basically it changes "4,8,9" to ",4,8,9," then looks for [something],4,[something]

this works better as [something]4[something] would find 4 or 40 or 14, and if we don't concat the comma's then 1,2,3,4 wouldn't work (no trailing comma)

Link to comment
Share on other sites

Two things --- first, DISTINCT is not a function, it's a modifier to SELECT; it filters out rows where ALL field values in the column list match.  Very different than GROUP BY.  Second, you can use FIND_IN_SET() if you values are comma separated without all that string manipulation.  But it's a bad idea to store lists in fields.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.