Want to implement such a read database function, how to do

Source: Internet
Author: User
Want to implement such a read database function, how to do
This post was last edited by Bnhxy on 2014-01-07 20:49:05

For example, I have two watches.
Table game has columns Gameid,gamename
There's data inside.
1. Gameid=1, Gamename=a
2. gameid=2, Gamename=b
3. gameid=3, Gamename=c

Table News has Newsid,news_title,gameid
There's data inside.
1. Newsid=1, NEWS_TITLE=ABC, gameid=1
2. newsid=2, News_title=def, gameid=1|2
3. newsid=3, News_title=ghi, gameid=1|2|3

Finally want to output all the news_title about GAMENAME=B

In addition to using like, what other good way to output, or how to build a table can achieve the corresponding effect?

Share to: more


------Solution--------------------
Select N.news_title from Game G, News n where G.gamename=b and InStr (N.gameid,g.gameid) >0
------Solution--------------------
Select Game.gameid, news.news_title from game, news
where game.gamename = ' B ' and Find_in_set (Game.gameid, replace (News.gameid, '
------Solution--------------------
', ','))

If News.gameid is not 1,
------Solution--------------------
2
------Solution--------------------
3 in this format, but the format is more ideal
------Solution--------------------
Select Game.gameid, news.news_title from game, news
where game.gamename = ' B ' and Find_in_set (Game.gameid, News.gameid)
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.