I have a standard SELECT query as follows:

SELECT eid, title, content, thumb_image FROM diary ORDER BY eid DESC LIMIT 3

...and a SELECT SUBTRING query as follows:

SELECT SUBSTRING(content, 1, 200) FROM diary

I'd like to combine the two so that it selects the latest 3 entries in the table and displays them with a limit of 200 characters. At the moment I've tried the following which has proven to ignore all entries that are more than 200 characters:

SELECT eid, title, content, thumb_image FROM diary WHERE content IN (SELECT SUBSTRING(content, 1, 200) FROM diary) ORDER BY eid DESC LIMIT 3

I've tried multiple variations of putting the substring query next to where content is selected with little success:

SELECT eid, title, content IN (SELECT SUBSTRING(content, 1, 200) FROM diary), thumb_image FROM diary ORDER BY eid DESC LIMIT 3
SELECT eid, title, content IN (SELECT SUBSTRING(content, 1, 200)), thumb_image FROM diary ORDER BY eid DESC LIMIT 3
SELECT eid, title, content IN (SELECT SUBSTRING(1, 200)), thumb_image FROM diary ORDER BY eid DESC LIMIT 3

Some help would be great, I offer virtual high fives as a reward ;) and maybe some rep power ;)

Recommended Answers

All 5 Replies

SELECT eid, title, SUBSTRING(content, 1, 200), thumb_image FROM diary ORDER BY eid DESC LIMIT 3

:) Now, gimme my virtual high five!

commented: Extremely helpful post ;) +1

*Venom Rush gives nav33n a virtual high five* ;)
Thanks a lot nav33n. Another rep point for you :cool:

:@ I want my reps! lol..

You are welcome ;)

Can't give u more rep nav33n. As much as I'd like to it's telling me I can't give you more rep today :|

I'll make a point of doing it tomorrow ;)

:(

LOL.. i know.. you have already given me reps for a php question(and you can give reps only once per day!)

commented: ro matt mere shair :P ye le rep! +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.