javis
javis

Reputation: 27

i want select name form one table and display in my page

SELECT name from tbl_gallery, tbl_gallery_category where 'name' = 'gallery-cat-id';

I have two tables one for category and second for saving images with category name my query is here Then executing thien shows MySQL returned an empty result set (i.e. zero rows). (Query took 0.0007 seconds.)

Upvotes: 0

Views: 40

Answers (2)

JYoThI
JYoThI

Reputation: 12085

Remove single quotes in name instead of 'name' read when to use single quotes, double quotes, and backticks

If you put single quotes on table or column name, they are treated as string so don't put.

SELECT `name` 
FROM tbl_gallery 
JOIN tbl_gallery_category ON tbl_gallery.name = tbl_gallery_category.gallery-cat-id;

Note :

where 'name' = 'gallery-cat-id';   

above where condition is always false only. Because your just comparing 'name' is equal to 'gallery-cat-id' so that it's false .

Upvotes: 2

juergen d
juergen d

Reputation: 204756

Don't use quotes on table or column names.

SELECT name 
from tbl_gallery
join tbl_gallery_category on tbl_gallery.name = tbl_gallery_category.`gallery-cat-id`

If you need to escape a column name then use backticks.

Upvotes: 2

Related Questions