mysql gurus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cyborg69
    So Fucking Banned
    • Apr 2002
    • 932

    #1

    mysql gurus

    i have table with site url, url, and text where are not unique
    and i need to select from the table something like this
    site url
    url1- tex1
    url2- tex2
    url3- tex3
    site2 url
    url1- tex1
    ....
    and so on well i can do this with 2 querries first selecting site url then with a limit selecting url and text but is it possible to do everything in one querry ?
  • icedemon
    Confirmed User
    • Jun 2003
    • 1022

    #2
    I'm not sure what your asking. You wanna show the 2 select statements your using and maybe explain what your trying to find? Are your trying to find text fields that match or what?
    Clips4Sale.com

    Comment

    • Cyborg69
      So Fucking Banned
      • Apr 2002
      • 932

      #3
      here is what i am doing right now
      SELECT DISTINCT surl FROM table WHERE text like '%something%'
      then i do
      SELECT text,url FROM table WHERE 1 AND `surl`= '$surl' AND text like '%something%' LIMIT 5

      i was wondering if its possible to join those 2 together

      Comment

      • TDJ
        Confirmed User
        • Nov 2003
        • 146

        #4
        You could if you were using postgres or a brand new beta mysql version, then you can use subselects:

        then i do
        SELECT text,url FROM table WHERE 1 AND surl IN (SELECT DISTINCT surl FROM table WHERE text like '%something%') AND text like '%something%' LIMIT 5

        Sounds like your table structure is poorly setup, else it should just be a matter of:

        SELECT a.whatever FROM tableA a, tableB b WHERE b.value='$blah' and a.id=b.id

        That might be too technical an explanation for you, sorry if so... Otherwise, using a 'stable' mysql release.. no.. no sub-selects.

        Comment

        • Cyborg69
          So Fucking Banned
          • Apr 2002
          • 932

          #5
          storing things in 2 different tables in not tha answer
          i need maximum 5 results from the same domain....

          Comment

          • icedemon
            Confirmed User
            • Jun 2003
            • 1022

            #6
            Have you tried using the GROUP BY function? I think you could do something like this

            SELECT text,url FROM table WHERE text LIKE '%something%' GROUP BY surl LIMIT 5

            You might have to group both the surl and text
            GROUP BY surl, text
            Clips4Sale.com

            Comment

            • Cyborg69
              So Fucking Banned
              • Apr 2002
              • 932

              #7
              limit will give only 5 overall results

              Comment

              • Cyborg69
                So Fucking Banned
                • Apr 2002
                • 932

                #8
                SELECT text,url FROM table WHERE text LIKE '%something%' GROUP BY surl LIMIT 5

                group by sulr make it same as
                SELECT distinc surl, text,url FROM table WHERE text LIKE '%something%' LIMIT 5

                Comment

                • icedemon
                  Confirmed User
                  • Jun 2003
                  • 1022

                  #9
                  Originally posted by Cyborg69
                  limit will give only 5 overall results
                  OK, I see what your doing now. I think your stuck with the way you've been doing it. If you were using Postgres, you could use Views.
                  Clips4Sale.com

                  Comment

                  • Cyborg69
                    So Fucking Banned
                    • Apr 2002
                    • 932

                    #10
                    can u give me an example how could i do this using Postgres

                    Comment

                    • icedemon
                      Confirmed User
                      • Jun 2003
                      • 1022

                      #11
                      Originally posted by Cyborg69
                      can u give me an example how could i do this using Postgres
                      You would basically create one VIEW (view1) with the first select that you have. Then create another VIEW (view2) to query view1. Then in your program or in Postgres, you just do a select on (view2).

                      Or you could just create the first VIEW (view1) and do a select on that. You can find more info at
                      http://www.postgresql.org/docs/curre...reateview.html

                      Basically, a VIEW is command (like SELECT) that is kinda made into a seperate table.
                      Clips4Sale.com

                      Comment

                      • fris
                        Too lazy to set a custom title
                        • Aug 2002
                        • 55700

                        #12
                        are you doing things from command line or using phpMyAdmin?

                        command line gave me headaches phpMyAdmin makes things a lot easier.
                        Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                        Comment

                        • Cyborg69
                          So Fucking Banned
                          • Apr 2002
                          • 932

                          #13
                          testing it in phpMyAdmin ,the script is in php

                          Comment

                          • KobyBoy
                            Confirmed User
                            • Jul 2003
                            • 201

                            #14
                            I understand what you are talking about. What you want is called a Sub Query. Yes, you can do it with MySQL. Here's a little tutorial I've found: http://www.onlamp.com/pub/a/onlamp/2.../aboutSQL.html

                            Comment

                            • KobyBoy
                              Confirmed User
                              • Jul 2003
                              • 201

                              #15
                              Here are two more links for you:

                              http://www.devshed.com/c/a/MySQL/Usi...-MySQL-part-1/

                              and

                              http://www.devshed.com/c/a/MySQL/Usi...-MySQL-part-2/

                              Comment

                              • Cyborg69
                                So Fucking Banned
                                • Apr 2002
                                • 932

                                #16
                                i could get what i was trying to with subquerries

                                Comment

                                • Cyborg69
                                  So Fucking Banned
                                  • Apr 2002
                                  • 932

                                  #17
                                  I have another example of what i need
                                  lets say a company has a list or all sales people and state their working in and i want to get the top 5 salesman from each state

                                  Comment

                                  • DrGuile
                                    Confirmed User
                                    • Jan 2002
                                    • 2025

                                    #18
                                    two tables would be the right way to do it.

                                    Seems like you have duplicating info in that table.
                                    LiveBucks / Privatefeeds - Giving you money since 1999
                                    Up to 50% Commission!
                                    25% Webmaster Referal
                                    Powered by Gamma

                                    Comment

                                    • Cyborg69
                                      So Fucking Banned
                                      • Apr 2002
                                      • 932

                                      #19
                                      one column has dublicated info and if i bring it out to a separete table it still won't make the job easier
                                      if u think u can do it with 2 tables write a querry...

                                      Comment

                                      • Cyborg69
                                        So Fucking Banned
                                        • Apr 2002
                                        • 932

                                        #20
                                        bump

                                        Comment

                                        • cube³
                                          Registered User
                                          • Dec 2003
                                          • 14

                                          #21
                                          .

                                          Pencils down, kids.

                                          select t1.url, t1.txt, t2.txt from tbl t1 inner join txt t2 on t1.url=t2.url where t1.txt like '%bl%' group by t1.url, t2.txt having t2.txt like '%bl%' limit 5;

                                          Don't you big players use Oracle? Come on... for the cost of just one of your Bentley's.

                                          -s
                                          Last edited by cube³; 01-27-2004, 03:08 PM.
                                          ±ß³ - (5327381)²

                                          Comment

                                          Working...