-3

I have a table "myTable" with lots of columns with one column called "listing_id".

I want to find the listings that start with "CG_"

Also I will like to have count how many such are there?

Hello Universe
  • 3,248
  • 7
  • 50
  • 86
  • 1
    You're using MySQL wrong. You **know** columns you need. You don't **ask** for columns, then select. Consider alternate permanent storage, something like Mongo or other types that don't have a schema. MySQL or RDBMS aren't for this usage scenario, unless you use EAV. – N.B. May 09 '14 at 11:56

3 Answers3

1
Select count(listing_id)
from mytable
where listing_id like 'CG_%';
G one
  • 2,679
  • 2
  • 14
  • 18
0

I would say you can use the information_schema as explained in here.

SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `COLUMN_NAME` like 'CG_%';
Community
  • 1
  • 1
Majid
  • 654
  • 2
  • 7
  • 28
0

unclear what are you asking..Thos query select all string like cg_% under listing_id

I want to find the listings that start with "CG_"

Also I will like to have count how many such are there?column

SELECT count(listing_id)
FROM tablename
WHERE listing_id LIKE 'cg_%'
Community
  • 1
  • 1
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53