Red Bridge Internet is a San Francisco WordPress Consulting firm specializing in WordPress websites and WordPress Plugin Development. We're the ones you have been searching for.

A MySQL Sub Select Wish

After doing a lot of searching and reading I think I came up empty on a subselect I wanted to do in MySQL. Here’s what I was trying to do:

tabel1
id rec
1 record 1
2 record 2

table2
t1id rec
1 val1
1 val2
2 val1

This is what I was trying to accomplish:

SELECT * FROM table1 WHERE id IN (SELECT * FROM table2 WHERE rec = val1);

I know there’s a million ways around this, with the correct 2 table syntax, a RIGHT JOIN, etc., but I was in this predicament where I just wanted to add to the original full select of SELECT * FROM table1.

No related posts.

Leave a Reply