Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Looping Database

by dug (Chaplain)
on Oct 16, 2002 at 18:55 UTC ( [id://205798]=note: print w/replies, xml ) Need Help??


in reply to Looping Database

Assuming that the field "category" in the table "items" corresponds to the field "id" in the table "category" and you want to solve this using SQL instead of Perl and you are using Mysql (may work on other databases as well, but untested) ...

which is a lot of assumtions :^)

You could use
SELECT items.* FROM items, category WHERE items.category = category.id + ORDER BY items.id DESC LIMIT 2;

If you are going to be doing a bit of database driven programming, it's certainly worth your time to spend a bit of time studying SQL. I'm just beginning to realize its power for certain tasks.

-- dug

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://205798]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found