homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Selecting multiple rows from a single table
neophyte




msg:4513092
 1:38 am on Oct 28, 2012 (gmt 0)

Hello All -

I've been trying various ways of selecting 2 rows of data from the same table, but nothing I do is working.

The only way I've got this to work is by doing 2 separate selects on this one table and then run queries on both selects (yuck!). I know there must be a way to do it (some kind of row join on the table?) but I can't get the syntax right.

The table contains 3 columns: fld_type, fld_04_hrs, and fld_08_hrs. What I want to do is get the 4 hour and 8 hour data for types 'Kayak - Single' AND 'Kayak - Double'.

This doesn't work, but sort of like:

$sql =
"SELECT fld_04_hrs, fld_08_hrs
FROM tbl_activities
WHERE fld_type = 'Kayak - Single' AND fld_type = 'Kayak - Double'";

The 2 selects that work are:

$sql =
"SELECT fld_04_hrs, fld_08_hrs
FROM tbl_activities
WHERE fld_type = 'Kayak - Single'";

...AND...

$sql =
"SELECT fld_04_hrs, fld_08_hrs
FROM tbl_activities
WHERE fld_type = 'Kayak - Double'";

But I'd really like to grab both pieces of data for both types in one select.

Can someone please show me how to do this?

Great appreciation in advance for anyone who can show me how this is done.

 

brotherhood of LAN




msg:4513094
 1:44 am on Oct 28, 2012 (gmt 0)

$sql =
"SELECT fld_04_hrs, fld_08_hrs
FROM tbl_activities
WHERE fld_type = 'Kayak - Single' OR fld_type = 'Kayak - Double'";

Your initial query is saying match both (by using AND) which is why no rows are returned. Use OR instead.

neophyte




msg:4513109
 1:58 am on Oct 28, 2012 (gmt 0)

Hello brotherhood of LAN -

Thanks for the fast reply.

I tried that select yesterday and I do get results but I only get 2 results (for Kayak - Single), not the 4 results I need (2 for kayak single and 2 for kayak double).

Indeed, I do need to match both... I think it can be solved with a self-join (or by some other means) but, like mentioned previously, I just can't seem to get the syntax correct.

topr8




msg:4513259
 7:03 pm on Oct 28, 2012 (gmt 0)

brotherhood of LAN is correct, you must be making another error somewhere.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved